semconv.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. ### Unstable SemConv
  3. <!-- Dev Note: ^^ This '#unstable-semconv' anchor is being used in jsdoc links in the code. -->
  4. 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.)
  5. 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):
  6. ```ts
  7. // src/semconv.ts
  8. export const ATTR_DB_NAMESPACE = 'db.namespace';
  9. export const ATTR_DB_OPERATION_NAME = 'db.operation.name';
  10. ```
  11. ```ts
  12. // src/instrumentation.ts
  13. import {
  14. ATTR_SERVER_PORT,
  15. ATTR_SERVER_ADDRESS,
  16. } from '@opentelemetry/semantic-conventions';
  17. import {
  18. ATTR_DB_NAMESPACE,
  19. ATTR_DB_OPERATION_NAME,
  20. } from './semconv';
  21. span.setAttributes({
  22. [ATTR_DB_NAMESPACE]: ...,
  23. [ATTR_DB_OPERATION_NAME]: ...,
  24. [ATTR_SERVER_PORT]: ...,
  25. [ATTR_SERVER_ADDRESS]: ...,
  26. })
  27. ```
  28. 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.
  29. */
  30. export const ATTR_SERVICE_INSTANCE_ID = 'service.instance.id';
  31. export const ATTR_HTTP_TARGET = 'http.target';