Replies: 3 comments
-
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT If I understand correctly, you want to use named options but if your config does not have a value you want to fall back to environment variable? Tagging @CodeBlanch to see if that is possible, he has more expertise in this area. |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for answering my question. Yeah that is correct, I want my application to fall back to the specific ENV variable OTEL_EXPORTER_OTLP_METRICS_ENDPOINT if it is set. As per current behavior it's setting the endpoint value to default (OTEL_EXPORTER_OTLP_ENDPOINT). |
Beta Was this translation helpful? Give feedback.
-
This confused me too for a while to after reviewing OpenTelemetry Protocol Exporter spec. I had assumed it would be picked up automatically. But from reading the dotnet spec page, if I use |
Beta Was this translation helpful? Give feedback.
-
I am trying to add OTLP exporter in my application so created a console application for testing. My application is successfully binding the configuration for signal specific metrics/tracing from a config.json file.
Program.cs
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using OpenTelemetry.Exporter;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
HostApplicationBuilder appBuilder = Host.CreateApplicationBuilder(args);
var configurationRoot = new ConfigurationBuilder()
.AddJsonFile("otlp.json")
.AddEnvironmentVariables()
.Build();
appBuilder.Services.Configure("tracing", configurationRoot.GetSection("OpenTelemetry:tracing:otlp"));
appBuilder.Services.Configure("metrics", configurationRoot.GetSection("OpenTelemetry:metrics:otlp"));
appBuilder.Services.AddOpenTelemetry()
.WithTracing(builder => builder.AddOtlpExporter("tracing", options =>
{
// Here the options values are default and override values from config.json
}))
.WithMetrics(builder => builder.AddOtlpExporter("metrics", options =>
{
// Here the options values are default and override values from config.json
}));
using IHost host = appBuilder.Build();
await host.RunAsync();
Config.josn format:
// {
// "OpenTelemetry": {
// "metrics": {
// "otlp": {
// "Endpoint": "http://otlpMetricsConfiguration:4317",
// "TimeoutMilliseconds": 30000
// }
// },
// "logging": {
// "otlp": {
// "Endpoint": "http://otlpLoggingConfiguration:4317",
// "TimeoutMilliseconds": 24000
// }
// },
// "tracing": {
// "otlp": {
// "Endpoint": "http://otlpTracingConfiguration:4317",
// "TimeoutMilliseconds": 24000
// }
// }
// }
// }
Question: My question is how the OTLP exporter bind the the ENV variables (OTEL_EXPORTER_OTLP_METRICS_ENDPOINT ) so we can use these if the config.json does not have a value. Options are getting the default values rather than the configuration specif values.
I did set the ENV variables.
OTEL_EXPORTER_OTLP_ENDPOINT=https://my-api-endpoint:443;
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=https://my-api-endpoint-metrics:443;
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://my-api-endpoint-traces:443
Thank you for any suggestions or guidance.
Beta Was this translation helpful? Give feedback.
All reactions