Skip to content
5 changes: 0 additions & 5 deletions content/en/opentelemetry/instrument/api_support/go.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Go
type: multi-code-lang
external_redirect: /opentelemetry/instrument/api_support/go/traces
---
172 changes: 172 additions & 0 deletions content/en/opentelemetry/instrument/api_support/go/metrics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
---
title: Go OpenTelemetry Metrics API Support
# Uncomment Metrics tab when Go metrics support is available
# code_lang: metrics
# type: multi-code-lang
# code_lang_weight: 1
further_reading:
- link: opentelemetry/correlate/metrics_and_traces
tag: Documentation
text: Correlate OpenTelemetry Traces and Metrics
---

## Overview

{{% otel-overview-exporter lang="Go" signal="Metrics" sdk_name="dd-trace-go" %}}

## Prerequisites

- **Datadog SDK**: dd-trace-go version 2.6.0 or later.
- **An OTLP-compatible destination**: You must have a destination (Agent or Collector) listening on ports 4317 (gRPC) or 4318 (HTTP) to receive OTel metrics.

## Setup

Follow these steps to enable OTel Metrics API support in your Go application.

1. Install the Datadog SDK:
```sh
go get github.com/DataDog/dd-trace-go/v2
```

2. Enable OTel metrics by setting the following environment variable:
```sh
export DD_METRICS_OTEL_ENABLED=true
```

3. Configure your application:
```go
import (
"context"
"time"

"github.com/DataDog/dd-trace-go/v2/ddtrace/opentelemetry/metric"
"go.opentelemetry.io/otel"
)

// Create MeterProvider with Datadog-specific defaults
mp, err := metric.NewMeterProvider()
if err != nil {
panic(err)
}

// Set as global MeterProvider
otel.SetMeterProvider(mp)

// Your application code here...

// Shutdown to flush remaining metrics
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
metric.Shutdown(ctx, mp)
```

## Examples

You can use the standard OpenTelemetry API packages to create custom metrics.

### Create a counter

This example uses the OTel Metrics API to create a counter that increments every time an item is processed:

```go
import (
"context"

"github.com/DataDog/dd-trace-go/v2/ddtrace/opentelemetry/metric"
"go.opentelemetry.io/otel"
otelmetric "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/attribute"
)

// Initialize MeterProvider (typically done once at startup)
mp, _ := metric.NewMeterProvider()
otel.SetMeterProvider(mp)

// Get a meter
meter := otel.Meter("my-service")

// Create a counter
counter, _ := meter.Int64Counter(
"http.requests_total",
otelmetric.WithDescription("Total number of HTTP requests"),
)

// Record measurements
counter.Add(context.Background(), 1,
attribute.String("method", "GET"),
attribute.String("status_code", "200"),
)
```

### Create a histogram

This example uses the OTel Metrics API to create a histogram to track request durations:

```go
import (
"context"
"time"

"go.opentelemetry.io/otel"
otelmetric "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/attribute"
)

// Get a meter (assuming MeterProvider is already configured)
meter := otel.Meter("my-service")

// Create a histogram
histogram, _ := meter.Float64Histogram(
"http.request_duration",
otelmetric.WithDescription("HTTP request duration"),
otelmetric.WithUnit("ms"),
)

// Measure request duration
start := time.Now()
// ... perform work ...
time.Sleep(50 * time.Millisecond)
duration := float64(time.Since(start).Nanoseconds()) / 1e6

histogram.Record(context.Background(), duration,
attribute.String("method", "POST"),
attribute.String("route", "/api/users"),
)
```

## Supported configuration

To enable this feature, you must set `DD_METRICS_OTEL_ENABLED=true`. Metrics are **disabled by default**.

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.

For a complete list of all shared OTLP environment variables, see [OpenTelemetry Environment Variables Interoperability][1].

## Migrate from other setups

### Existing OTel setup

If you are using the OTel SDK with your own manual OTLP exporter configuration:

1. Add the Datadog SDK (`dd-trace-go/v2`) to your project and enable its instrumentation.
2. Remove any code that manually configures the `OTLPMetricsExporter`. The Datadog SDK handles this configuration automatically.
3. Set the `DD_METRICS_OTEL_ENABLED=true` environment variable.

### Existing DogStatsD setup

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.

**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 `dd-trace-go` implementation supports exporting OTLP metrics exclusively to a Datadog Agent or OpenTelemetry Collector. Multiple exporters are not supported.

## Troubleshooting

{{% otel-api-troubleshooting signal="metrics" %}}
- Verify `DD_METRICS_OTEL_ENABLED=true` is set. Metrics are disabled by default in dd-trace-go.
- Ensure the Datadog SDK is imported: `import "github.com/DataDog/dd-trace-go/v2/ddtrace/opentelemetry/metric"`
{{% /otel-api-troubleshooting %}}

## Further reading

{{< partial name="whats-next/whats-next.html" >}}

[1]: /opentelemetry/config/environment_variable_support
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Go OpenTelemetry Traces API Support
code_lang: traces
type: multi-code-lang
code_lang_weight: 0
---

{{< include-markdown "/tracing/trace_collection/custom_instrumentation/go/otel/" >}}
5 changes: 0 additions & 5 deletions content/en/opentelemetry/instrument/api_support/php.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: PHP
type: multi-code-lang
external_redirect: /opentelemetry/instrument/api_support/php/traces
---
126 changes: 126 additions & 0 deletions content/en/opentelemetry/instrument/api_support/php/metrics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
title: PHP OpenTelemetry Metrics API Support
# Uncomment Metrics tab when PHP metrics support is available
# code_lang: metrics
# type: multi-code-lang
# code_lang_weight: 1
further_reading:
- link: opentelemetry/correlate/metrics_and_traces
tag: Documentation
text: Correlate OpenTelemetry Traces and Metrics
---

## Overview

{{% otel-overview-exporter lang="PHP" signal="Metrics" sdk_name="dd-trace-php" %}}

**Note**: PHP OpenTelemetry Metrics API support is not yet available.

## Prerequisites

- **Datadog SDK**: dd-trace-php version 1.16.0 or later.
- **OpenTelemetry PHP SDK**: Version 1.0.0 or later (`open-telemetry/sdk`).
- **OpenTelemetry OTLP Exporter**: The OTLP exporter package (`open-telemetry/exporter-otlp`).
- **An OTLP-compatible destination**: You must have a destination (Agent or Collector) listening on ports 4317 (gRPC) or 4318 (HTTP) to receive OTel metrics.

## Setup

### 1. Install the required packages

Follow these steps to enable OTel Metrics API support in your PHP application.

1. Install the Datadog PHP tracer following the [official installation instructions][2].

2. Install the required OpenTelemetry packages:

```sh
composer require open-telemetry/sdk
composer require open-telemetry/exporter-otlp
```

### 2. Enable OpenTelemetry Metrics

Set the `DD_METRICS_OTEL_ENABLED` environment variable to enable OpenTelemetry Metrics support:

```sh
export DD_METRICS_OTEL_ENABLED=true
```

Alternatively, set it in your `php.ini`:

```php
datadog.metrics_otel_enabled = true
```

### 3. Configure your application:

The Datadog SDK automatically configures the OpenTelemetry MeterProvider when your application loads. No additional code configuration is required.

If your Datadog Agent is running on a non-default location, configure the endpoint:

# Option 1: Using the Agent URL
```sh
export DD_TRACE_AGENT_URL=http://your-agent-host:8126
```

# Option 2: Using the Agent host
```sh
export DD_AGENT_HOST=your-agent-host
```

The SDK automatically resolves the appropriate OTLP endpoint (port 4318 for HTTP, port 4317 for gRPC).

## Examples

### Create a counter

This example uses the OTel Metrics API to create a counter that increments every time a request is processed:

```php
use OpenTelemetry\API\Globals;

// dd-trace-php automatically configures the MeterProvider
$meter = Globals::meterProvider()->getMeter('my-service');
$counter = $meter->createCounter('requests', 'requests', 'Total number of requests');
$counter->add(1, ['method' => 'GET', 'route' => '/api/users']);
```

## Supported configuration

To enable this feature, you must set `DD_METRICS_OTEL_ENABLED=true` (or `datadog.metrics_otel_enabled = true` in php.ini).

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.

For a complete list of all shared OTLP environment variables, see [OpenTelemetry Environment Variables Interoperability][1].

## Migrate from other setups

### Existing OTel setup

If you are using the OTel SDK with your own manual OTLP exporter configuration:

1. Install the Datadog PHP tracer following the [official installation instructions][2].
2. Remove any code that manually configures the OTLP exporter. The Datadog SDK handles this configuration automatically.
3. Set the `DD_METRICS_OTEL_ENABLED=true` environment variable.

### Existing DogStatsD setup

If you are currently using the Datadog DogStatsD client and want to migrate to the OpenTelemetry Metrics API, update your instrumentation code to use the OTel Meter API instead of StatsD client calls.

## Troubleshooting

{{% otel-api-troubleshooting signal="metrics" %}}

- Verify OpenTelemetry SDK version. Version 1.0.0 or later is required.
- Ensure `open-telemetry/exporter-otlp` package is installed.
- Ensure `DD_METRICS_OTEL_ENABLED=true` is set before your application starts.
- Enable debug logging with `DD_TRACE_DEBUG=true` to see detailed logs.

{{% /otel-api-troubleshooting %}}

## Further reading

{{< partial name="whats-next/whats-next.html" >}}

[1]: /opentelemetry/config/environment_variable_support
[2]: /tracing/trace_collection/dd_libraries/php/#install-the-extension
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: PHP OpenTelemetry Traces API Support
code_lang: traces
type: multi-code-lang
code_lang_weight: 0
---

{{< include-markdown "/tracing/trace_collection/custom_instrumentation/php/otel/" >}}
5 changes: 0 additions & 5 deletions content/en/opentelemetry/instrument/api_support/rust.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Rust
type: multi-code-lang
external_redirect: /opentelemetry/instrument/api_support/rust/traces
---
Loading
Loading