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

Why is the parentId of the called service not the one of the caller service? #5491

Open
snake-L opened this issue Mar 29, 2024 · 2 comments
Open
Labels
question Further information is requested

Comments

@snake-L
Copy link

snake-L commented Mar 29, 2024

Question

image
image
image
How did Service A call Service B, Service B call Service C, and the parentIDs of Service B and C get?

@snake-L snake-L added the question Further information is requested label Mar 29, 2024
@martinjt
Copy link
Member

martinjt commented Apr 1, 2024

There's not a huge amount of information to go on there, but I suspect that the ParentIds are from the HTTP outbound span (HTTP Client), not the inbound AspNet core span, which is what you're showing there.

I'm not sure why ServiceC would be in a new Trace, but perhaps you've not enabled the HTTPClient instrumentation in Service B?

@snake-L
Copy link
Author

snake-L commented Apr 8, 2024

There's not a huge amount of information to go on there, but I suspect that the ParentIds are from the HTTP outbound span (HTTP Client), not the inbound AspNet core span, which is what you're showing there.

I'm not sure why ServiceC would be in a new Trace, but perhaps you've not enabled the HTTPClient instrumentation in Service B?

@martinjt hi, this is the sample code. I have checked the source code but cannot find the reason

serviceA

	var builder = WebApplication.CreateBuilder(args);
	builder.WebHost.ConfigureKestrel(b =>
{
	b.ListenAnyIP(5000);
});
	builder.Services.AddHttpClient();
	builder.Services.AddOpenTelemetry()
	.ConfigureResource(resource => resource
		.AddService("ServiceA"))
	.WithTracing(tracing => tracing
		.AddAspNetCoreInstrumentation()
		.AddConsoleExporter()
		.AddZipkinExporter()
		);

	var app = builder.Build();
	app.MapGet("/serviceA", async Task<string> (HttpContext context, IHttpClientFactory factory) =>
	{
		using var httpClient = factory.CreateClient("client");
		httpClient.BaseAddress = new Uri("Http://localhost:5001");
		
		var response = await httpClient.GetAsync("/serviceB");
		response.EnsureSuccessStatusCode();
		return await response.Content.ReadAsStringAsync();
	});
	await app.RunAsync();

serviceB

  var builder = WebApplication.CreateBuilder(args);
	builder.WebHost.ConfigureKestrel(b =>
{
	b.ListenAnyIP(5001);
});
	builder.Services.AddHttpClient();
	builder.Services.AddOpenTelemetry()
	.ConfigureResource(resource => resource
		.AddService("ServiceB"))
	.WithTracing(tracing => tracing
		.AddAspNetCoreInstrumentation()
		.AddConsoleExporter().AddZipkinExporter()
		);
	var app = builder.Build();
	app.MapGet("/serviceB", async Task<string> (HttpContext context, IHttpClientFactory factory) =>
	{
		using var httpClient = factory.CreateClient("serviceC");
		httpClient.BaseAddress = new Uri("Http://localhost:5002");

		var response = await httpClient.GetAsync("/serviceC");
		response.EnsureSuccessStatusCode();
		var result =  await response.Content.ReadAsStringAsync();


	    response = await httpClient.GetAsync("/serviceC");
		response.EnsureSuccessStatusCode();
        return await response.Content.ReadAsStringAsync();
	});
	await app.RunAsync();

ServiceC

	var builder = WebApplication.CreateBuilder(args);
	builder.WebHost.ConfigureKestrel(b =>
{
	b.ListenAnyIP(5002);
});
	builder.Services.AddHttpClient();
	builder.Services.AddOpenTelemetry()
	.ConfigureResource(resource => resource
		.AddService("ServiceC"))
	.WithTracing(tracing => tracing
		.AddAspNetCoreInstrumentation()
				.AddConsoleExporter().AddZipkinExporter()
		);

	var app = builder.Build();
	app.MapGet("/serviceC", ValueTask<string> (HttpContext context) =>
{
	return new ValueTask<string>($"DateTime Now:{DateTime.Now},GUid:{Guid.NewGuid().ToString("N")}");
});
	await app.RunAsync();

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