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

service.name is defined as unknown_service #5551

Closed
jmurrayrs opened this issue Apr 18, 2024 · 2 comments
Closed

service.name is defined as unknown_service #5551

jmurrayrs opened this issue Apr 18, 2024 · 2 comments
Labels
question Further information is requested

Comments

@jmurrayrs
Copy link

I'm configuring an Action in .NET 8 setting service name:

Action<ResourceBuilder> configureResource = r => r.AddService(
            serviceName: "xpto",
            serviceVersion: settings.ServiceVersion,
            serviceInstanceId: Environment.MachineName);

and I'm registering here

serviceCollection.
            .AddOpenTelemetry()
            .ConfigureResource(configureResource)
             .WithTracing(builder =>
                        {
                            builder                           
                                .AddNpgsql()
                                .AddEntityFrameworkCoreInstrumentation(options =>
                                {
                                    options.EnrichWithIDbCommand = (activity, command) =>
                                    {
                                        //var stateDisplayName = $"{command.CommandType} main";
                                        var stateDisplayName = command.GetType().FullName;
                                        activity.DisplayName = stateDisplayName!;
                                        activity.SetTag("db.name", stateDisplayName);
                                    };
                                })
                                .AddAspNetCoreInstrumentation(opts =>
                                {
                                    opts.EnrichWithHttpRequest = (a, r) => a?.AddTag("env", environmentName);
                                    opts.RecordException = true;
            
                                })
                                .AddOtlpExporter(config =>
                                {
                                    config.Endpoint = new Uri(settings.Exporter.Endpoint);
                                })
                                .AddConsoleExporter();
            
                        })
                        .WithMetrics(builder =>
                        {
                            builder
                                .AddMeter(metrics.Name)
                                .AddRuntimeInstrumentation()
                                .AddAspNetCoreInstrumentation()
                                .AddOtlpExporter(config =>
                                {
                                    config.Endpoint = new Uri(settings.Exporter.Endpoint ?? string.Empty);
                                })
                                .AddConsoleExporter();
                        });

But, when I see the logs, the service.name is unknown_service

  "resources": {
    "service.name": "unknown_service:dotnet",
    "telemetry.sdk.language": "dotnet",
    "telemetry.sdk.name": "serilog",
    "telemetry.sdk.version": "1.2.0"
  },

How Can I set the service name correctly ?

Thanks !

@jmurrayrs jmurrayrs added the question Further information is requested label Apr 18, 2024
@reyang
Copy link
Member

reyang commented Apr 18, 2024

@jmurrayrs I think in your code the Action was applied to metrics and traces, but not logs.

logging.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(

@reyang
Copy link
Member

reyang commented Apr 18, 2024

Feel free to reopen the issue if #5551 (comment) didn't help to solve the problem.

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

2 participants