What is @opentelemetry/semantic-conventions?
The @opentelemetry/semantic-conventions package provides standardized naming and semantic conventions for attributes in OpenTelemetry. These conventions help ensure that telemetry data is consistent, interpretable, and analyzable across different systems and services. The package includes constants for resource attributes, span attributes, and event names that are recommended by the OpenTelemetry specification.
What are @opentelemetry/semantic-conventions's main functionalities?
Resource Attributes
Defines standard attributes to be used for service resources, allowing you to annotate your telemetry data with information about the service instance.
{"service.name": 'my-service', "service.version": '1.0.0', "service.instance.id": 'instance-123'}
Span Attributes
Provides a set of standard attributes for spans, which represent individual operations within a trace. These attributes can be used to add metadata about the operation, such as HTTP method, URL, and status code.
{"http.method": 'GET', "http.url": 'https://example.com', "http.status_code": 200}
Event Names
Includes standardized event names for logging exceptions, messages, and metrics within spans. This helps in categorizing and querying telemetry events.
"exception", "message", "metric"
Other packages similar to @opentelemetry/semantic-conventions
elastic-apm-node
Elastic APM Node.js Agent is a real user monitoring library that provides similar functionality to OpenTelemetry. It allows you to instrument your Node.js applications to track performance metrics and errors. While it also adheres to certain conventions, it is tailored to work with the Elastic Stack, and may not be as flexible as OpenTelemetry in terms of vendor neutrality.
jaeger-client
Jaeger client libraries provide features for distributed tracing similar to OpenTelemetry. They offer their own set of conventions for tracing data. While Jaeger is compatible with OpenTelemetry through exporters, its native conventions are not the same as those defined by OpenTelemetry's semantic conventions.
OpenTelemetry Semantic Conventions
Semantic Convention constants for use with the OpenTelemetry SDK/APIs. This document defines standard attributes for traces.
Installation
npm install --save @opentelemetry/semantic-conventions
Usage
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
const span = tracer.startSpan().startSpan(spanName, spanOptions)
.setAttributes({
[SemanticAttributes.NET_PEER_NAME]: 'localhost',
});
Useful links
License
Apache 2.0 - See LICENSE for more information.