Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load OtlpExportProtocol from IConfigure #5626

Closed
minimalisticMe opened this issue May 17, 2024 · 1 comment
Closed

Load OtlpExportProtocol from IConfigure #5626

minimalisticMe opened this issue May 17, 2024 · 1 comment
Labels
question Further information is requested

Comments

@minimalisticMe
Copy link

What is the question?

Hi,

I want to configure the OtlpExporter from configuration file.

The following snippet harcoded without configuration file works for me:

options.AddOtlpExporter(exporter =>
{
    exporter.Endpoint = new Uri("http://localhost:5341/ingest/otlp/v1/logs");
    exporter.Protocol = OtlpExportProtocol.HttpProtobuf;
});

However when I follow the documentation and add a json-file with the following content:

{
  "OpenTelemetry": {
    "OtlpLogging": {
      "Endpoint": "http://localhost:5341/ingest/otlp/v1/logs",
      "OtlpExportProtocol": "http/protobuf"
    },
    "OtlpTracing": {
      "Endpoint": "http://localhost:5341/ingest/otlp/v1/traces"
    }
  }
}

and add it to the code like this:

services.Configure<OtlpExporterOptions>("OtlpLogging",
    otlpConfiguration.GetSection("OpenTelemetry:OtlpLogging"));
services.Configure<OtlpExporterOptions>("OtlpTracing",
    otlpConfiguration.GetSection("OpenTelemetry:OtlpTracing"));

services.AddLogging(logging => logging.AddOpenTelemetry(options =>
{
    options.SetResourceBuilder(ResourceBuilder.CreateEmpty()
        .AddService("MyService"));

    options.IncludeScopes = true;
    options.IncludeFormattedMessage = true;

    options.AddOtlpExporter(name: "OtlpLogging", configure: null);
}));

I cannot see logs on my endpoint (Seq) anymore.
I think the issue might be in parsing OtlpExportProtocol from the json-file and I tried the following values for it without success:

  • 1
  • "http/protobuf"
  • "HttpProtobuf"

How do I configure the OtlpExporter with json-file correctly?

Additional context

No response

@minimalisticMe minimalisticMe added the question Further information is requested label May 17, 2024
@minimalisticMe
Copy link
Author

I was using the wrong public member to map to. There is auto-mapping of enum-values from json-files.
The correct file would look like this:

{
  "OpenTelemetry": {
    "OtlpLogging": {
      "Endpoint": "http://localhost:5341/ingest/otlp/v1/logs",
      "Protocol": "HttpProtobuf"
    },
    "OtlpTracing": {
      "Endpoint": "http://localhost:5341/ingest/otlp/v1/traces"
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant