### Example: Kitchen Sink Configuration Source: https://opentelemetry.io/docs/specs/otel/configuration/types This example demonstrates a comprehensive configuration including file format, attribute limits, and logger provider settings with overriding limits. ```yaml file_format: "1.1" attribute_limits: attribute_value_length_limit: 2048 attribute_count_limit: 64 logger_provider: processors: - simple: exporter: console: limits: # .logger_provider.limits take priority over general .attribute_limits. In this contrived example, attribute_value_length_limit is set to 4096, attribute_count_limit is set to 128, overriding the values from general .attribute_limits. attribute_count_limit: 128 attribute_value_length_limit: 4096 ``` -------------------------------- ### Kubernetes Pod Entity Example Source: https://opentelemetry.io/docs/specs/otel/entities/entity-propagation Shows an example of specifying a Kubernetes pod entity with its UID, name, and app label. ```bash OTEL_ENTITIES="k8s.pod{k8s.pod.uid=pod-abc123}[k8s.pod.name=my-pod,k8s.pod.label.app=my-app]" ``` -------------------------------- ### Kitchen Sink Configuration Example Source: https://opentelemetry.io/docs/specs/otel/configuration/types An example demonstrating a full configuration including meter provider, console exporter, and specific meter configurations with enabled/disabled settings. ```yaml file_format: "1.1" meter_provider: readers: - periodic: exporter: console: meter_configurator/development: default_config: enabled: false meters: - name: io.opentelemetry.contrib.* config: enabled: true ``` -------------------------------- ### Full View Configuration Example Source: https://opentelemetry.io/docs/specs/otel/configuration/types This example demonstrates a comprehensive view configuration, specifying detailed criteria for instrument selection and stream properties, including custom histogram buckets. The `selector` and `stream` properties are required. ```yaml file_format: "1.1" meter_provider: readers: - periodic: exporter: console: views: - selector: instrument_name: my_instrument instrument_type: histogram unit: ms meter_name: my-meter meter_version: 1.0.0 meter_schema_url: https://opentelemetry.io/schemas/1.16.0 stream: name: new_instrument_name description: new_description aggregation: explicit_bucket_histogram: boundaries: - 0.0 - 5.0 - 10.0 - 25.0 - 50.0 - 75.0 - 100.0 - 250.0 - 500.0 - 750.0 - 1000.0 - 2500.0 - 5000.0 - 7500.0 - 10000.0 record_min_max: true aggregation_cardinality_limit: 2000 attribute_keys: included: - foo.* excluded: - foo.bar ``` -------------------------------- ### Meter Configuration Example Source: https://opentelemetry.io/docs/specs/otel-config/types An example demonstrating how to configure meter providers, including setting a default meter configuration and specific configurations for meters matching a wildcard pattern. This configuration is written in YAML. ```yaml file_format: "1.1" meter_provider: readers: - periodic: exporter: console: meter_configurator/development: default_config: enabled: false meters: - name: io.opentelemetry.contrib.* config: enabled: true ``` -------------------------------- ### OtlpGrpcMetricExporter Configuration Example Source: https://opentelemetry.io/docs/specs/otel/configuration/types Example demonstrating how to configure the OtlpGrpcMetricExporter with various settings like endpoint, TLS, headers, compression, and timeout. ```yaml file_format: "1.1" meter_provider: readers: - periodic: exporter: otlp_grpc: endpoint: http://localhost:4317 tls: ca_file: /app/cert.pem key_file: /app/cert.pem cert_file: /app/cert.pem insecure: false headers: - name: api-key value: "1234" headers_list: "api-key=1234" compression: gzip timeout: 10000 ``` -------------------------------- ### Container with Host Entity Example Source: https://opentelemetry.io/docs/specs/otel/entities/entity-propagation/index.md Provides an example of propagating both container and host entities, with minimal descriptive attributes for the host. ```bash OTEL_ENTITIES="container{container.id=cont-456};host{host.id=host-789}[host.name=docker-host]" ``` -------------------------------- ### Container with Host Entity Example Source: https://opentelemetry.io/docs/specs/otel/entities/entity-propagation An example defining a container entity and a host entity, including minimal descriptive attributes for the host. ```bash OTEL_ENTITIES="container{container.id=cont-456};host{host.id=host-789}[host.name=docker-host]" ``` -------------------------------- ### YAML Configuration Example with Null Property Source: https://opentelemetry.io/docs/specs/otel/configuration/sdk/index.md Example demonstrating a configuration where a property is present but null, requiring the SDK to treat it as a valid configuration. ```yaml meter_provider: views: - selector: name: some.metric.name stream: aggregation: drop: ``` -------------------------------- ### Python3 TraceIdRatioBased Sampler Example Source: https://opentelemetry.io/docs/specs/otel/trace/tracestate-probability-sampling This Python3 example illustrates the logic for a TraceIdRatioBased sampler. It is provided for clarity and not as a recommended implementation. ```python from opentelemetry.sdk.trace import Sampler from opentelemetry.sdk.trace.sampling import TraceIdRatioBased class TraceIdRatioBasedSampler(Sampler): def __init__(self, ratio: float): if not 0.0 <= ratio <= 1.0: raise ValueError("ratio must be between 0.0 and 1.0") self.ratio = ratio self.trace_id_ratio_based = TraceIdRatioBased(ratio) def should_sample(self, parent_context, trace_id, name, kind, attributes, links): # The following logic is a workaround for the underspecified behavior # and is safe to use for root spans (in combination with ParentBased). # Different language SDKs or even different versions of the same language # SDKs may produce inconsistent results for the same input. if parent_context is None: return self.trace_id_ratio_based.should_sample( parent_context, trace_id, name, kind, attributes, links ) else: # For spans with a parent, delegate to the parent sampler. # This ensures consistent sampling decisions when using ParentBased. return parent_context.sampling_result # Example usage: # sampler = TraceIdRatioBasedSampler(0.5) # Sample 50% of traces ``` -------------------------------- ### OpenTelemetry Schema File Example Source: https://opentelemetry.io/docs/specs/otel/schemas/file_format_v1.1.0 Example configuration file defining schema versioning and attribute transformation rules for resources, spans, and metrics. ```yaml # Defines the file format. MUST be set to 1.1.0. file_format: 1.1.0 # The Schema URL that this file is published at. The version number in the URL # MUST match the highest version number in the "versions" section below. # Note: the schema version number in the URL is not related in any way to # the file_format setting above. schema_url: /schemas/1.1.0 # Definitions for each schema version in this family. # Note: the ordering of versions is defined according to semver # version number ordering rules. versions: 1.1.0: # Definitions for version 1.1.0. all: # Definitions that apply to all data types. changes: # Transformations to apply when converting from version 1.0.0 to 1.1.0. - rename_attributes: # map of key/values. The keys are the old attribute name used # the previous version, the values are the new attribute name # starting from this version. # Rename k8s.* to kubernetes.* k8s.cluster.name: kubernetes.cluster.name k8s.namespace.name: kubernetes.namespace.name k8s.node.name: kubernetes.node.name k8s.node.uid: kubernetes.node.uid k8s.pod.name: kubernetes.pod.name k8s.pod.uid: kubernetes.pod.uid k8s.container.name: kubernetes.container.name k8s.replicaset.name: kubernetes.replicaset.name k8s.replicaset.uid: kubernetes.replicaset.uid k8s.cronjob.name: kubernetes.cronjob.name k8s.cronjob.uid: kubernetes.cronjob.uid k8s.job.name: kubernetes.job.name k8s.job.uid: kubernetes.job.uid k8s.statefulset.name: kubernetes.statefulset.name k8s.statefulset.uid: kubernetes.statefulset.uid k8s.daemonset.name: kubernetes.daemonset.name k8s.daemonset.uid: kubernetes.daemonset.uid k8s.deployment.name: kubernetes.deployment.name k8s.deployment.uid: kubernetes.deployment.uid resources: # Definitions that apply to Resource data type. changes: - rename_attributes: telemetry.auto.version: telemetry.auto_instr.version spans: # Definitions that apply to Span data type. changes: - rename_attributes: attribute_map: # map of key/values. The keys are the old attribute name used # in the previous version, the values are the new attribute name # starting from this version. peer.service: peer.service.name apply_to_spans: # apply only to spans named "HTTP GET" - "HTTP GET" span_events: # Definitions that apply to Span Event data type. changes: - rename_events: # The keys are old event name used in the previous version, the # values are the new event name starting from this version. name_map: {stacktrace: stack_trace} - rename_attributes: attribute_map: peer.service: peer.service.name apply_to_events: # Optional event names to apply to. If empty applies to all events. - exception.stack_trace metrics: # Definitions that apply to Metric data type. changes: - rename_metrics: # map of key/values. The keys are the old metric name used # in the previous version, the values are the new metric name # starting from this version. container.cpu.usage.total: cpu.usage.total container.memory.usage.max: memory.usage.max - rename_attributes: attribute_map: status: state apply_to_metrics: # Optional. If it is missing the transformation is applied # to all metrics. If it is present the transformation is applied # only to the metrics with the name that is found in the sequence # specified below. - system.cpu.utilization - system.memory.usage - system.memory.utilization - system.paging.usage ``` -------------------------------- ### Create Counter Instruments Source: https://opentelemetry.io/docs/specs/otel/metrics/api Examples of creating Counter instruments using Meter instances in Python and C#. ```python exception_counter = meter.create_counter(name="exceptions", description="number of exceptions caught", value_type=int) ``` ```csharp var counterExceptions = meter.CreateCounter("exceptions", description="number of exceptions caught"); readonly struct PowerConsumption { [HighCardinality] string customer; }; var counterPowerUsed = meter.CreateCounter("power_consumption", unit="kWh"); ``` -------------------------------- ### Create Counter Instruments Source: https://opentelemetry.io/docs/specs/otel/metrics/api/index.md Examples of how to instantiate a Counter using a Meter instance in Python and C#. ```python # Python exception_counter = meter.create_counter(name="exceptions", description="number of exceptions caught", value_type=int) ``` ```csharp // C# var counterExceptions = meter.CreateCounter("exceptions", description="number of exceptions caught"); readonly struct PowerConsumption { [HighCardinality] string customer; }; var counterPowerUsed = meter.CreateCounter("power_consumption", unit="kWh"); ``` -------------------------------- ### Environment Variable Configuration Source: https://opentelemetry.io/docs/specs/otel/configuration/data-model/index.md Example environment variable settings used to demonstrate substitution behavior. ```shell export STRING_VALUE="value" export BOOL_VALUE="true" export INT_VALUE="1" export FLOAT_VALUE="1.1" export HEX_VALUE="0xdeadbeef" # A valid integer value (i.e. 3735928559) written in hexadecimal export INVALID_MAP_VALUE="value\nkey:value" # An invalid attempt to inject a map key into the YAML export DO_NOT_REPLACE_ME="Never use this value" # An unused environment variable export REPLACE_ME='${DO_NOT_REPLACE_ME}' # A valid replacement text, used verbatim, not replaced with "Never use this value" export VALUE_WITH_ESCAPE='value$$' # A valid variable substituted without escaping ``` -------------------------------- ### Initialize SDK via Configuration API Source: https://opentelemetry.io/docs/specs/otel/configuration/sdk/index.md Demonstrates parsing a single configuration file and creating SDK components. ```java OpenTelemetry openTelemetry = OpenTelemetry.noop(); try { // Parse configuration file to configuration model OpenTelemetryConfiguration configurationModel = parse(new File("/app/sdk-config.yaml")); // Create SDK components from configuration model openTelemetry = create(configurationModel); } catch (Throwable e) { log.error("Error initializing SDK from configuration file", e); } // Access SDK components and install instrumentation TracerProvider tracerProvider = openTelemetry.getTracerProvider(); MeterProvider meterProvider = openTelemetry.getMeterProvider(); LoggerProvider loggerProvider = openTelemetry.getLoggerProvider(); ContextPropagators propagators = openTelemetry.getPropagators(); ConfigProvider configProvider = openTelemetry.getConfigProvider(); ``` -------------------------------- ### Example Schema File Configuration Source: https://opentelemetry.io/docs/specs/otel/schemas/file_format_v1.1.0/index.md A sample YAML configuration showing the required file_format and schema_url settings. ```yaml # Defines the file format. MUST be set to 1.1.0. file_format: 1.1.0 # The Schema URL that this file is published at. The version number in the URL # MUST match the highest version number in the "versions" section below. # Note: the schema version number in the URL is not related in any way to # the file_format setting above. schema_url: /schemas/1.1.0 # Definitions for each schema version in this family. # Note: the ordering of versions is defined according to semver ``` -------------------------------- ### Export All Metrics with Default Configuration Source: https://opentelemetry.io/docs/specs/otel/metrics/sdk This example demonstrates exporting all metrics using the default configuration by simply adding a metric reader. ```Python meter_provider.add_metric_reader(PeriodicExportingMetricReader(ConsoleExporter())) ``` -------------------------------- ### Initialize SDK via OTEL_CONFIG_FILE Source: https://opentelemetry.io/docs/specs/otel/configuration/sdk/index.md Configures the SDK using the OTEL_CONFIG_FILE environment variable. ```shell # Set the required env var to the location of the configuration file export OTEL_CONFIG_FILE="/app/sdk-config.yaml" ``` ```java // Initialize SDK using autoconfigure model, which recognizes that OTEL_CONFIG_FILE is set and configures the SDK accordingly OpenTelemetry openTelemetry = AutoConfiguredOpenTelemetrySdk.initialize().getOpenTelemetrySdk(); // Access SDK components and install instrumentation TracerProvider tracerProvider = openTelemetry.getTracerProvider(); MeterProvider meterProvider = openTelemetry.getMeterProvider(); LoggerProvider loggerProvider = openTelemetry.getLoggerProvider(); ContextPropagators propagators = openTelemetry.getPropagators(); ConfigProvider configProvider = openTelemetry.getConfigProvider(); ``` -------------------------------- ### Example YAML Configuration Source: https://opentelemetry.io/docs/specs/otel/configuration/sdk/index.md A sample configuration file defining a tracer provider with a batch span processor and OTLP HTTP exporter. ```yaml file_format: 1.0 tracer_provider: processors: - batch: exporter: otlp_http: ``` -------------------------------- ### Multiple Entities with Schema URL Example Source: https://opentelemetry.io/docs/specs/otel/entities/entity-propagation Demonstrates how to define multiple entities, including a service and a host, with a schema URL for the service. ```bash OTEL_ENTITIES="service{service.name=my-app,service.instance.id=instance-1}[service.version=1.0.0]@/schemas/1.21.0;host{host.id=host-123}[host.name=web-server-01]" ``` -------------------------------- ### Configure OTLP gRPC Exporter for Tracer Provider Source: https://opentelemetry.io/docs/specs/otel/configuration/types Example of configuring the OTLP gRPC exporter for a tracer provider. This configuration mirrors the logger provider example, demonstrating consistent settings for tracing. ```yaml file_format: "1.1" tracer_provider: processors: - batch: exporter: otlp_grpc: endpoint: http://localhost:4317 tls: ca_file: /app/cert.pem key_file: /app/cert.pem cert_file: /app/cert.pem insecure: false headers: - name: api-key value: "1234" headers_list: "api-key=1234" compression: gzip timeout: 10000 ``` -------------------------------- ### Start a new Span Source: https://opentelemetry.io/docs/specs/otel/compatibility/opentracing Starts a new span with the given operation name, references, tags, and optional start timestamp. For languages implementing ScopeManager, an additional boolean parameter controls automatic parent ignoring. Baggage from references or the current context is propagated. Tags are set at creation time, and the 'error' tag is handled specifically. Timestamps are converted to match units. ```APIDOC ## Start a new Span ### Description Starts a new span with the given operation name, references, tags, and optional start timestamp. For languages implementing ScopeManager, an additional boolean parameter controls automatic parent ignoring. Baggage from references or the current context is propagated. Tags are set at creation time, and the 'error' tag is handled specifically. Timestamps are converted to match units. ### Parameters - `operationName` (string) - The operation name. - `references` (list of Span references, optional) - An optional list of Span references. - `tags` (list of tags, optional) - An optional list of tags. - `startTime` (numeric, optional) - An explicit start timestamp. - `ignoreActiveSpan` (boolean, optional) - Specifies whether the current `Span` should be ignored as automatic parent (for ScopeManager implementations). ### Returns - An OpenTracing `Span`. ``` -------------------------------- ### Example Schema File Configuration Source: https://opentelemetry.io/docs/specs/otel/schemas/file_format_v1.0.0/index.md This snippet shows the 'file_format' setting, which must be set to '1.0.0'. It also includes 'schema_url' and version definitions. ```yaml # Defines the file format. MUST be set to 1.0.0. file_format: 1.0.0 # The Schema URL that this file is published at. The version number in the URL # MUST match the highest version number in the "versions" section below. # Note: the schema version number in the URL is not related in any way to # the file_format setting above. schema_url: /schemas/1.1.0 # Definitions for each schema version in this family. # Note: the ordering of versions is defined according to semver ``` -------------------------------- ### Multiple Entities with Schema URL Example Source: https://opentelemetry.io/docs/specs/otel/entities/entity-propagation/index.md Shows how to define multiple entities, including a service and a host, with a schema URL for the service entity. ```bash OTEL_ENTITIES="service{service.name=my-app,service.instance.id=instance-1}[service.version=1.0.0]@/schemas/1.21.0;host{host.id=host-123}[host.name=web-server-01]" ``` -------------------------------- ### Prometheus Exporter Configuration Example Source: https://opentelemetry.io/docs/specs/otel-config/types Example configuration for the Prometheus exporter using YAML format. It demonstrates setting host, port, scope and target info enablement, resource labels, and translation strategy. ```yaml file_format: "1.1" meter_provider: readers: - pull: exporter: prometheus/development: host: localhost port: 9464 scope_info_enabled: true target_info_enabled/development: true resource_constant_labels: included: - "service*" excluded: - "service.attr1" translation_strategy: underscore_escaping_with_suffixes ``` -------------------------------- ### Merge Multiple Configurations via API Source: https://opentelemetry.io/docs/specs/otel/configuration/sdk/index.md Shows how to parse multiple configuration sources, merge them, and initialize the SDK. ```java OpenTelemetry openTelemetry = OpenTelemetry.noop(); try { // Parse local and remote configuration files to configuration models OpenTelemetryConfiguration localConfigurationModel = parse(new File("/app/sdk-config.yaml")); OpenTelemetryConfiguration remoteConfigurationModel = parse(getRemoteConfiguration("http://example-host/config/my-application")); // Merge the configuration models using custom logic OpenTelemetryConfiguration resolvedConfigurationModel = merge(localConfigurationModel, remoteConfigurationModel); // Create SDK components from resolved configuration model openTelemetry = create(resolvedConfigurationModel); } catch (Throwable e) { log.error("Error initializing SDK from configuration file", e); } // Access SDK components and install instrumentation TracerProvider tracerProvider = openTelemetry.getTracerProvider(); MeterProvider meterProvider = openTelemetry.getMeterProvider(); LoggerProvider loggerProvider = openTelemetry.getLoggerProvider(); ContextPropagators propagators = openTelemetry.getPropagators(); ConfigProvider configProvider = openTelemetry.getConfigProvider(); ``` -------------------------------- ### Attribute Collection Examples (JSON) Source: https://opentelemetry.io/docs/specs/otel/common Illustrates various ways to represent attribute collections as JSON objects for non-OTLP protocols. These examples show empty, simple, and complex attribute collections including nested structures and null values. ```json {} ``` ```json { "http.request.method": "GET", "retries": 3 } ``` ```json { "payload": "aGVsbG8gd29ybGQ=", "session.id": null } ``` ```json { "colors": ["red", "blue"], "context": {"nested": true} } ``` -------------------------------- ### Example Log Data in OTLP Format Source: https://opentelemetry.io/docs/specs/otel/protocol/file-exporter This snippet shows an example of log data structured according to the OpenTelemetry Protocol (OTLP). It includes resource attributes, scope information, and individual log records with timestamps, severity, body, and attributes. ```json {"resourceLogs":[{"resource":{"attributes":[{"key":"resource-attr","value":{"stringValue":"resource-attr-val-1"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1581452773000000789","severityNumber":9,"severityText":"Info","body":{"stringValue":"This is a log message"},"attributes":[{"key":"app","value":{"stringValue":"server"}},{"key":"instance_num","value":{"intValue":"1"}}],"droppedAttributesCount":1,"traceId":"08040201000000000000000000000000","spanId":"0102040800000000"},{"timeUnixNano":"1581452773000000789","severityNumber":9,"severityText":"Info","body":{"stringValue":"something happened"},"attributes":[{"key":"customer","value":{"stringValue":"acme"}},{"key":"env","value":{"stringValue":"dev"}}],"droppedAttributesCount":1,"traceId":"","spanId":""}]}]}]} ``` ```json {"resourceLogs":[{"resource":{"attributes":[{"key":"resource-attr","value":{"stringValue":"resource-attr-val-1"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1581452773000001233","severityNumber":9,"severityText":"Info","body":{"stringValue":"This is a log message"},"attributes":[{"key":"app","value":{"stringValue":"server"}},{"key":"instance_num","value":{"intValue":"1"}}],"droppedAttributesCount":1,"traceId":"08040201000000000000000000000000","spanId":"0102040800000000"},{"timeUnixNano":"1581452773000000789","severityNumber":9,"severityText":"Info","body":{"stringValue":"something happened"},"attributes":[{"key":"customer","value":{"stringValue":"acme"}},{"key":"env","value":{"stringValue":"dev"}}],"droppedAttributesCount":1,"traceId":"","spanId":""}]}]}]} ``` ```json {"resourceLogs":[{"resource":{"attributes":[{"key":"resource-attr","value":{"stringValue":"resource-attr-val-1"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1581452773000005443","severityNumber":9,"severityText":"Info","body":{"stringValue":"This is a log message"},"attributes":[{"key":"app","value":{"stringValue":"server"}},{"key":"instance_num","value":{"intValue":"1"}}],"droppedAttributesCount":1,"traceId":"08040201000000000000000000000000","spanId":"0102040800000000"},{"timeUnixNano":"1581452773000000789","severityNumber":9,"severityText":"Info","body":{"stringValue":"something happened"},"attributes":[{"key":"customer","value":{"stringValue":"acme"}},{"key":"env","value":{"stringValue":"dev"}}],"droppedAttributesCount":1,"traceId":"","spanId":""}]}]}]} ``` ```json {"resourceLogs":[{"resource":{"attributes":[{"key":"resource-attr","value":{"stringValue":"resource-attr-val-1"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1581452773000009875","severityNumber":9,"severityText":"Info","body":{"stringValue":"This is a log message"},"attributes":[{"key":"app","value":{"stringValue":"server"}},{"key":"instance_num","value":{"intValue":"1"}}],"droppedAttributesCount":1,"traceId":"08040201000000000000000000000000","spanId":"0102040800000000"},{"timeUnixNano":"1581452773000000789","severityNumber":9,"severityText":"Info","body":{"stringValue":"something happened"},"attributes":[{"key":"customer","value":{"stringValue":"acme"}},{"key":"env","value":{"stringValue":"dev"}}],"droppedAttributesCount":1,"traceId":"","spanId":""}]}]}]} ``` -------------------------------- ### Example OTLP Metrics Data Source: https://opentelemetry.io/docs/specs/otel/protocol/file-exporter This snippet shows an example of telemetry data in OTLP format, specifically focusing on metrics. It demonstrates the structure for resource metrics, scope metrics, and individual metric data points including sums and attributes. ```json {"resourceMetrics":[{"resource":{"attributes":[{"key":"resource-attr","value":{"stringValue":"resource-attr-val-1"}}]},"scopeMetrics":[{"scope":{},"metrics":[{"name":"counter-int","unit":"1","sum":{"dataPoints":[{"attributes":[{"key":"label-1","value":{"stringValue":"label-value-1"}}],"startTimeUnixNano":"1581452773000000789","timeUnixNano":"1581452773000000789","asInt":"123"},{"attributes":[{"key":"label-2","value":{"stringValue":"label-value-2"}}],"startTimeUnixNano":"1581452772000000321","timeUnixNano":"1581452773000000789","asInt":"456"}],"aggregationTemporality":2,"isMonotonic":true}},{"name":"counter-int","unit":"1","sum":{"dataPoints":[{"attributes":[{"key":"label-1","value":{"stringValue":"label-value-1"}}],"startTimeUnixNano":"1581452772000000321","timeUnixNano":"1581452773000000789","asInt":"123"},{"attributes":[{"key":"label-2","value":{"stringValue":"label-value-2"}}],"startTimeUnixNano":"1581452772000000321","timeUnixNano":"1581452773000000789","asInt":"456"}],"aggregationTemporality":2,"isMonotonic":true}}]}]}]} ``` ```json {"resourceMetrics":[{"resource":{"attributes":[{"key":"resource-attr","value":{"stringValue":"resource-attr-val-1"}}]},"scopeMetrics":[{"scope":{},"metrics":[{"name":"counter-int","unit":"1","sum":{"dataPoints":[{"attributes":[{"key":"label-1","value":{"stringValue":"label-value-1"}}],"startTimeUnixNano":"1581452773000001459","timeUnixNano":"1581452773000001459","asInt":"120"},{"attributes":[{"key":"label-2","value":{"stringValue":"label-value-2"}}],"startTimeUnixNano":"1581452773000001459","timeUnixNano":"1581452773000001459","asInt":"456"}],"aggregationTemporality":2,"isMonotonic":true}},{"name":"counter-int","unit":"1","sum":{"dataPoints":[{"attributes":[{"key":"label-1","value":{"stringValue":"label-value-1"}}],"startTimeUnixNano":"1581452773000001459","timeUnixNano":"1581452773000001459","asInt":"123"},{"attributes":[{"key":"label-2","value":{"stringValue":"label-value-2"}}],"startTimeUnixNano":"1581452773000001459","timeUnixNano":"1581452773000001459","asInt":"456"}],"aggregationTemporality":2,"isMonotonic":true}}]}]}]} ``` ```json {"resourceMetrics":[{"resource":{"attributes":[{"key":"resource-attr","value":{"stringValue":"resource-attr-val-1"}}]},"scopeMetrics":[{"scope":{},"metrics":[{"name":"counter-int","unit":"1","sum":{"dataPoints":[{"attributes":[{"key":"label-1","value":{"stringValue":"label-value-1"}}],"startTimeUnixNano":"1581452773000002346","timeUnixNano":"1581452773000002346","asInt":"121"},{"attributes":[{"key":"label-2","value":{"stringValue":"label-value-2"}}],"startTimeUnixNano":"1581452773000002346","timeUnixNano":"1581452773000002346","asInt":"456"}],"aggregationTemporality":2,"isMonotonic":true}},{"name":"counter-int","unit":"1","sum":{"dataPoints":[{"attributes":[{"key":"label-1","value":{"stringValue":"label-value-1"}}],"startTimeUnixNano":"1581452773000002346","timeUnixNano":"1581452773000002346","asInt":"123"},{"attributes":[{"key":"label-2","value":{"stringValue":"label-value-2"}}],"startTimeUnixNano":"1581452772000000321","timeUnixNano":"1581452773000000789","asInt":"456"}],"aggregationTemporality":2,"isMonotonic":true}}]}]}]} ``` ```json {"resourceMetrics":[{"resource":{"attributes":[{"key":"resource-attr","value":{"stringValue":"resource-attr-val-1"}}]},"scopeMetrics":[{"scope":{},"metrics":[{"name":"counter-int","unit":"1","sum":{"dataPoints":[{"attributes":[{"key":"label-1","value":{"stringValue":"label-value-1"}}],"startTimeUnixNano":"1581452773000007891","timeUnixNano":"1581452773000007891","asInt":"125"},{"attributes":[{"key":"label-2","value":{"stringValue":"label-value-2"}}],"startTimeUnixNano":"1581452772000000321","timeUnixNano":"1581452773000007891","asInt":"456"}],"aggregationTemporality":2,"isMonotonic":true}},{"name":"counter-int","unit":"1","sum":{"dataPoints":[{"attributes":[{"key":"label-1","value":{"stringValue":"label-value-1"}}],"startTimeUnixNano":"1581452773000007891","timeUnixNano":"1581452773000007891","asInt":"123"},{"attributes":[{"key":"label-2","value":{"stringValue":"label-value-2"}}],"startTimeUnixNano":"1581452772000000321","timeUnixNano":"1581452773000007891","asInt":"456"}],"aggregationTemporality":2,"isMonotonic":true}}]}]}]} ``` -------------------------------- ### Create an UpDownCounter Source: https://opentelemetry.io/docs/specs/otel/metrics/api/index.md Examples of creating an UpDownCounter instrument in Python and C#. ```python # Python customers_in_store = meter.create_up_down_counter( name="grocery.customers", description="measures the current customers in the grocery store", value_type=int) ``` ```csharp // C# var customersInStore = meter.CreateUpDownCounter( "grocery.customers", description: "measures the current customers in the grocery store", ); ``` -------------------------------- ### Create a Histogram Source: https://opentelemetry.io/docs/specs/otel/metrics/api Examples of creating a histogram instrument using language-specific patterns. ```python http_server_duration = meter.create_histogram( name="http.server.duration", description="measures the duration of the inbound HTTP request", unit="ms", value_type=float) ``` ```csharp var httpServerDuration = meter.CreateHistogram( "http.server.duration", description: "measures the duration of the inbound HTTP request", unit: "ms" ); ``` -------------------------------- ### Record Histogram Values Source: https://opentelemetry.io/docs/specs/otel/metrics/api/index.md Examples of recording values with associated attributes in Python and C#. ```python # Python http_server_duration.Record(50, {"http.request.method": "POST", "url.scheme": "https"}) http_server_duration.Record(100, http_method="GET", http_scheme="http") ``` ```csharp // C# httpServerDuration.Record(50, ("http.request.method", "POST"), ("url.scheme", "https")); httpServerDuration.Record(100, new HttpRequestAttributes { method = "GET", scheme = "http" }); ```