semconv.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* eslint-disable max-len */
  2. /*
  3. ### Unstable SemConv
  4. <!-- Dev Note: ^^ This '#unstable-semconv' anchor is being used in jsdoc links in the code. -->
  5. Because the "incubating" entry-point may include breaking changes in minor versions, it is recommended that instrumentation libraries **not** import `@opentelemetry/semantic-conventions/incubating` in runtime code, but instead **copy relevant definitions into their own code base**. (This is the same [recommendation](https://opentelemetry.io/docs/specs/semconv/non-normative/code-generation/#stability-and-versioning) as for other languages.)
  6. For example, create a "src/semconv.ts" (or "lib/semconv.js" if implementing in JavaScript) file that copies from [experimental_attributes.ts](./src/experimental_attributes.ts) or [experimental_metrics.ts](./src/experimental_metrics.ts):
  7. ```ts
  8. // src/semconv.ts
  9. export const ATTR_DB_NAMESPACE = 'db.namespace';
  10. export const ATTR_DB_OPERATION_NAME = 'db.operation.name';
  11. ```
  12. ```ts
  13. // src/instrumentation.ts
  14. import {
  15. ATTR_SERVER_PORT,
  16. ATTR_SERVER_ADDRESS,
  17. } from '@opentelemetry/semantic-conventions';
  18. import {
  19. ATTR_DB_NAMESPACE,
  20. ATTR_DB_OPERATION_NAME,
  21. } from './semconv';
  22. span.setAttributes({
  23. [ATTR_DB_NAMESPACE]: ...,
  24. [ATTR_DB_OPERATION_NAME]: ...,
  25. [ATTR_SERVER_PORT]: ...,
  26. [ATTR_SERVER_ADDRESS]: ...,
  27. })
  28. ```
  29. Occasionally, one should review changes to `@opentelemetry/semantic-conventions` to see if any used unstable conventions have changed or been stabilized. However, an update to a newer minor version of the package will never be breaking.
  30. */
  31. export const ATTR_SERVICE_INSTANCE_ID = 'service.instance.id';
  32. export const ATTR_HTTP_TARGET = 'http.target';