Skip to main content
Module

x/slack_web_api/src/instrument.ts

Slack Developer Kit for Node.js
Go to Latest
File
import { name, version } from '../config.ts'
/** * Replaces occurrences of '/' with ':' in a string, since '/' is meaningful inside User-Agent strings as a separator. */function replaceSlashes(s: string): string { return s.replace('/', ':')}
const baseUserAgent = `${replaceSlashes(name)}/${version} ` + `deno/${Deno.version.deno} ` + `${Deno.build.os}`
const appMetadata: { [key: string]: string } = {}
/** * Appends the app metadata into the User-Agent value * @param appMetadata.name - name of tool to be counted in instrumentation * @param appMetadata.version - version of tool to be counted in instrumentation */export function addAppMetadata({ name, version }: { name: string, version: string }): void { appMetadata[replaceSlashes(name)] = version}
/** * Returns the current User-Agent value for instrumentation */export function getUserAgent(): string { const appIdentifier = Object.entries(appMetadata).map(([name, version]) => `${name}/${version}`).join(' ') // only prepend the appIdentifier when its not empty return ((appIdentifier.length > 0) ? `${appIdentifier} ` : '') + baseUserAgent}