Skip to content

Commit 30d0d7c

Browse files
authored
Deprecate use of GRAFANA_CLOUD_* environment variables in code and documentation (#87)
* Deprecate GRAFANA_CLOUD_ environment variables * Remove obsolete tests * Fix warnings * Add changelog * Linter issues * Linter fixes
1 parent 1f5a927 commit 30d0d7c

File tree

7 files changed

+125
-80
lines changed

7 files changed

+125
-80
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@
99
* [#85](https://github.com/grafana/grafana-opentelemetry-dotnet/pull/85)
1010
Adds resource detectors for Azure, host, process, process runtime, and
1111
container resource attributes.
12+
* [#87](https://github.com/grafana/grafana-opentelemetry-dotnet/pull/87)
13+
Add a new `OtlpExporter` class supporting specifying OTLP protocol, endpoint,
14+
and header
15+
16+
### Deprecation
17+
18+
* [#87](https://github.com/grafana/grafana-opentelemetry-dotnet/pull/87)
19+
Deprecate use of `GRAFANA_CLOUD_*` environment variables in code and documentation
20+
21+
The use of `CloudOtlpExporter` and `GRAFANA_CLOUD_*` environment variables is
22+
deprecated. Instead use `OtlpExporter` for code-level configuration, and
23+
`OTEL_EXPORTER_OTLP_PROTOCOL`, `OTEL_EXPORTER_OTLP_ENDPOINT`, and
24+
`OTEL_EXPORTER_OTLP_HEADERS` for configuration via environment variables.
1225

1326
## 0.7.0-beta.3
1427

README.md

+11-21
Original file line numberDiff line numberDiff line change
@@ -42,35 +42,25 @@ The `UseGrafana` extension method on the `TracerProviderBuilder` or the
4242
default, telemetry data will be sent to a Grafana agent or an OTel collector
4343
that runs locally and listens to default OTLP ports.
4444

45-
Given the zone, instance ID, and API token, telemetry data can be sent directly
46-
to the Grafana Cloud without involving an agent or collector:
47-
4845
```csharp
4946
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
50-
.UseGrafana(config =>
51-
{
52-
config.ExporterSettings = new CloudOtlpExporter
53-
{
54-
Zone = "prod-us-east-0",
55-
InstanceId = "123456",
56-
ApiKey = "a-secret-token"
57-
};
58-
})
47+
.UseGrafana()
5948
.Build();
6049
```
6150

62-
For details on how to obtain those values, refer to [Sending data directly to
63-
Grafana Cloud via
64-
OTLP](./docs/configuration.md#sending-data-directly-to-grafana-cloud-via-otlp).
51+
Alternatively, you can send telemetry data directly to Grafana Cloud without
52+
involving an agent or collector. This can be configured via the environment
53+
variables `OTEL_EXPORTER_OTLP_PROTOCOL`, `OTEL_EXPORTER_OTLP_ENDPOINT`, and
54+
`OTEL_EXPORTER_OTLP_HEADERS`.
6555

66-
Alternatively, these values can be set via the environment variables
67-
`GRAFANA_CLOUD_ZONE`, `GRAFANA_CLOUD_INSTANCE_ID`, and
68-
`GRAFANA_CLOUD_API_KEY`.
56+
For details on how to obtain those values, refer to [Push directly from
57+
applications using the OpenTelemetry
58+
SDKs](https://grafana.com/docs/grafana-cloud/send-data/otlp/send-data-otlp/#push-directly-from-applications-using-the-opentelemetry-sdks).
6959

7060
```sh
71-
export GRAFANA_CLOUD_ZONE=prod-us-east-0
72-
export GRAFANA_CLOUD_INSTANCE_ID=123456
73-
export GRAFANA_CLOUD_API_KEY=a-secret-token
61+
export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
62+
export OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp-gateway-prod-eu-west-0.grafana.net/otlp"
63+
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic a-secret-token"
7464
```
7565

7666
## Documentation

docs/configuration.md

+13-21
Original file line numberDiff line numberDiff line change
@@ -121,35 +121,30 @@ to the Grafana Cloud without involving an agent or collector:
121121
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
122122
.UseGrafana(config =>
123123
{
124-
config.ExporterSettings = new CloudOtlpExporter
124+
config.ExporterSettings = new OtlpExporter
125125
{
126-
Zone = "prod-us-east-0",
127-
InstanceId = "123456",
128-
ApiKey = "a-secret-token"
126+
Protocol = OpenTelemetry.Exporter.OtlpExportProtocol.HttpProtobuf,
127+
Endpoint = Uri("https://otlp-gateway-prod-eu-west-0.grafana.net/otlp"),
128+
Headers = "Authorization=Basic a-secret-token"
129129
};
130130
})
131131
.Build();
132132
```
133133

134-
Follow the following steps to obtain the zone, instance id, and an API token:
135-
136-
1. Click **Details** in the **Grafana** section on
137-
<https://grafana.com/profile/org>.
138-
2. You will see values for **Instance ID** and **Zone** on this page.
139-
3. On the left menu, click on **Security** and then on **API Keys**
140-
4. Obtain a new API token by clicking on **Create API Key** (`MetricsPublisher`
141-
role).
142-
143134
Alternatively, these values can be set via the environment variables
144-
`GRAFANA_CLOUD_ZONE`, `GRAFANA_CLOUD_INSTANCE_ID`, and
145-
`GRAFANA_CLOUD_API_KEY`.
135+
`OTEL_EXPORTER_OTLP_PROTOCOL`, `OTEL_EXPORTER_OTLP_ENDPOINT`, and
136+
`OTEL_EXPORTER_OTLP_HEADERS`.
146137

147138
```sh
148-
export GRAFANA_CLOUD_ZONE=prod-us-east-0
149-
export GRAFANA_CLOUD_INSTANCE_ID=123456
150-
export GRAFANA_CLOUD_API_KEY=a-secret-token
139+
export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
140+
export OTEL_EXPORTER_OTLP_ENDPOINT="https://otlp-gateway-prod-eu-west-0.grafana.net/otlp"
141+
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic a-secret-token"
151142
```
152143

144+
For details on how to obtain those values, refer to [Push directly from
145+
applications using the OpenTelemetry
146+
SDKs](https://grafana.com/docs/grafana-cloud/send-data/otlp/send-data-otlp/#push-directly-from-applications-using-the-opentelemetry-sdks).
147+
153148
## Instrumentation configuration
154149

155150
### Disabling instrumentations
@@ -314,6 +309,3 @@ are not contained in the distribution.
314309
| Variable | Example value | Description |
315310
| ----------------------------------------- | ------------------ | ----------- |
316311
| `GRAFANA_DOTNET_DISABLE_INSTRUMENTATIONS` | "Process,NetRuntime" | A comma-separated list of instrumentations to disable. |
317-
| `GRAFANA_CLOUD_ZONE` | "prod-us-east-0" | Zone of the Grafana Cloud stack to send data to. |
318-
| `GRAFANA_CLOUD_INSTANCE_ID` | "123456" | Instance ID of the Grafana Cloud stack to send data to. |
319-
| `GRAFANA_CLOUD_API_KEY` | | API key of the Grafana Cloud Stack to send data to. |

src/Grafana.OpenTelemetry.Base/ExporterSettings/CloudOtlpExporter.cs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Grafana.OpenTelemetry
1515
/// <summary>
1616
/// Settings for exporting telemetry directly to Grafana Agent via OTLP.
1717
/// </summary>
18+
[Obsolete("This class is obsolete. Use OtlpExporter instead.")]
1819
public class CloudOtlpExporter : ExporterSettings
1920
{
2021
internal const string ZoneEnvVarName = "GRAFANA_CLOUD_ZONE";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//
2+
// Copyright Grafana Labs
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
6+
using System;
7+
using Microsoft.Extensions.Configuration;
8+
using OpenTelemetry.Exporter;
9+
using OpenTelemetry.Logs;
10+
using OpenTelemetry.Metrics;
11+
using OpenTelemetry.Trace;
12+
13+
namespace Grafana.OpenTelemetry
14+
{
15+
/// <summary>
16+
/// Settings for exporting telemetry via plain OTLP exporter settings.
17+
/// </summary>
18+
public class OtlpExporter : ExporterSettings
19+
{
20+
/// <summary>
21+
/// Gets or sets the target to which the exporter is going to send telemetry.
22+
/// Must be a valid Uri with scheme (http or https) and host, and
23+
/// may contain a port and path.
24+
/// </summary>
25+
public Uri Endpoint { get; set; }
26+
27+
/// <summary>
28+
/// Gets or sets optional headers for the connection. Refer to the <a href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#specifying-headers-via-environment-variables">specification</a> for information on the expected format for Headers.
29+
/// </summary>
30+
public string Headers { get; set; }
31+
32+
/// <summary>
33+
/// Gets or sets the the OTLP transport protocol. Supported values: Grpc and HttpProtobuf
34+
/// </summary>
35+
public OtlpExportProtocol Protocol { get; set; }
36+
37+
/// <inheritdoc/>
38+
override internal void Apply(TracerProviderBuilder builder)
39+
{
40+
if (EnableTraces == false)
41+
{
42+
return;
43+
}
44+
45+
builder.AddOtlpExporter(config =>
46+
{
47+
config.Endpoint = new Uri($"{Endpoint}/v1/traces");
48+
config.Headers = Headers;
49+
config.Protocol = Protocol;
50+
});
51+
}
52+
53+
/// <inheritdoc/>
54+
override internal void Apply(MeterProviderBuilder builder)
55+
{
56+
if (EnableMetrics == false)
57+
{
58+
return;
59+
}
60+
61+
builder.AddOtlpExporter(config =>
62+
{
63+
config.Endpoint = new Uri($"{Endpoint}/v1/metrics");
64+
config.Headers = Headers;
65+
config.Protocol = Protocol;
66+
});
67+
}
68+
69+
/// <inheritdoc/>
70+
override internal void Apply(OpenTelemetryLoggerOptions options)
71+
{
72+
if (EnableLogs == false)
73+
{
74+
return;
75+
}
76+
77+
options.AddOtlpExporter(config =>
78+
{
79+
config.Endpoint = new Uri($"{Endpoint}/v1/logs");
80+
config.Headers = Headers;
81+
config.Protocol = Protocol;
82+
});
83+
}
84+
}
85+
}

src/Grafana.OpenTelemetry.Base/GrafanaOpenTelemetrySettings.cs

+2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ internal GrafanaOpenTelemetrySettings(IConfiguration configuration)
8989
{
9090
try
9191
{
92+
#pragma warning disable CS0618
9293
ExporterSettings = new CloudOtlpExporter();
94+
#pragma warning restore CS0618
9395
}
9496
catch (Exception)
9597
{

tests/Grafana.OpenTelemetry.Tests/CloudOtlpExporterTest.cs

-38
This file was deleted.

0 commit comments

Comments
 (0)