Skip to content

Commit 79711d0

Browse files
committed
chore(ddtrace/otel): document metrics support in rust, php, go
1 parent 45e6fa0 commit 79711d0

File tree

4 files changed

+134
-5
lines changed

4 files changed

+134
-5
lines changed

content/en/opentelemetry/instrument/api_support/rust.md

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Rust
3+
type: multi-code-lang
4+
external_redirect: /opentelemetry/instrument/api_support/rust/traces
5+
---
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
---
2+
title: Rust OpenTelemetry Metrics API Support
3+
code_lang: metrics
4+
type: multi-code-lang
5+
code_lang_weight: 1
6+
private: true
7+
further_reading:
8+
- link: opentelemetry/correlate/metrics_and_traces
9+
tag: Documentation
10+
text: Correlate OpenTelemetry Traces and Metrics
11+
---
12+
13+
## Overview
14+
15+
{{% otel-overview-exporter lang="Rust" signal="Metrics" sdk_name="datadog-opentelemetry" %}}
16+
17+
**Note**: Metrics support will be available in datadog-opentelemetry v0.4.0.
18+
19+
## Prerequisites
20+
21+
- **Datadog SDK**: `datadog-opentelemetry` crate version 0.4.0 or later.
22+
- **Rust**: MSRV 1.84 or later.
23+
- **An OTLP-compatible destination**: You must have a destination (Agent or Collector) listening on ports 4317 (gRPC) or 4318 (HTTP) to receive OTel metrics.
24+
25+
## Setup
26+
27+
Follow these steps to enable OTel Metrics API support in your Rust application.
28+
29+
1. Add the Datadog SDK to your Cargo.toml:
30+
```toml
31+
[dependencies]
32+
datadog-opentelemetry = { version = "0.4.0" }
33+
opentelemetry = { version = "0.31", features = ["metrics"] }
34+
```
35+
36+
2. Enable OTel metrics by setting the following environment variable:
37+
```sh
38+
export DD_METRICS_OTEL_ENABLED=true
39+
```
40+
41+
3. Configure your application:
42+
```rust
43+
use std::time::Duration;
44+
45+
// Enable metrics via environment variable
46+
std::env::set_var("DD_METRICS_OTEL_ENABLED", "true");
47+
48+
// Initialize metrics with default configuration
49+
let meter_provider = datadog_opentelemetry::metrics().init();
50+
51+
// Your application code here...
52+
53+
// Shutdown to flush remaining metrics
54+
meter_provider.shutdown().unwrap();
55+
```
56+
57+
## Examples
58+
59+
You can use the standard OpenTelemetry API packages to create custom metrics.
60+
61+
### Create a counter
62+
63+
This example uses the OTel Metrics API to create a counter that increments every time an item is processed:
64+
65+
```rust
66+
use opentelemetry::global;
67+
use opentelemetry::metrics::Counter;
68+
use opentelemetry::KeyValue;
69+
70+
// datadog-opentelemetry automatically configures the MeterProvider
71+
let meter = global::meter("my-service");
72+
let counter: Counter<u64> = meter.u64_counter("requests").build();
73+
counter.add(1, &[KeyValue::new("method", "GET")]);
74+
```
75+
76+
## Supported configuration
77+
78+
To enable this feature, you must set `DD_METRICS_OTEL_ENABLED=true`.
79+
80+
All OTLP exporter settings (such as endpoints, protocols, and timeouts), resource attributes, and temporality preferences are configured using a shared set of OpenTelemetry environment variables.
81+
82+
### Transport Features
83+
84+
The default feature includes gRPC transport. Additional transport options:
85+
86+
- For gRPC transport: `features = ["metrics-grpc"]` (default)
87+
- For HTTP transport: `features = ["metrics-http"]`
88+
89+
**Note**: HTTP/JSON protocol is not supported. Use `grpc` or `http/protobuf` protocols only.
90+
91+
For a complete list of all shared OTLP environment variables, see [OpenTelemetry Environment Variables Interoperability][1].
92+
93+
## Migrate from other setups
94+
95+
### Existing OTel setup
96+
97+
If you are using the OTel SDK with your own manual OTLP exporter configuration:
98+
99+
1. Add the Datadog SDK (`datadog-opentelemetry`) to your project and enable its instrumentation.
100+
2. Remove any code that manually configures the `OTLPMetricsExporter`. The Datadog SDK handles this configuration automatically.
101+
3. Set the `DD_METRICS_OTEL_ENABLED=true` environment variable.
102+
103+
### Existing DogStatsD setup
104+
105+
If you are currently using the Datadog DogStatsD client and want to migrate to the OpenTelemetry Metrics API, you need to update your instrumentation code. The main difference is that OTel metrics are configured using environment variables rather than code, and you create `Instrument` objects first.
106+
107+
**Important**: Runtime and trace metrics continue to be submitted using StatsD. Only custom metrics created through the OpenTelemetry Metrics API are sent using OTLP. The `datadog-opentelemetry` implementation supports exporting OTLP metrics exclusively to a Datadog Agent or OpenTelemetry Collector. Multiple exporters are not supported.
108+
109+
## Troubleshooting
110+
111+
{{% otel-api-troubleshooting signal="metrics" %}}
112+
- Verify transport features are enabled. Ensure `metrics-grpc` or `metrics-http` feature is enabled in your Cargo.toml depending on your protocol choice.
113+
- Check protocol configuration. Only `grpc` and `http/protobuf` protocols are supported. HTTP/JSON is not supported.
114+
- Ensure `DD_METRICS_OTEL_ENABLED=true` is set before initializing the meter provider.
115+
{{% /otel-api-troubleshooting %}}
116+
117+
## Further reading
118+
119+
{{< partial name="whats-next/whats-next.html" >}}
120+
121+
[1]: /opentelemetry/config/environment_variable_support
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Rust OpenTelemetry Traces API Support
3+
code_lang: traces
4+
type: multi-code-lang
5+
code_lang_weight: 0
6+
---
7+
8+
{{< include-markdown "/tracing/trace_collection/custom_instrumentation/rust/" >}}

0 commit comments

Comments
 (0)