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

Automatically trace outgoing requests for traced request #9941

Closed
Zopitirik opened this issue Feb 22, 2023 · 6 comments
Closed

Automatically trace outgoing requests for traced request #9941

Zopitirik opened this issue Feb 22, 2023 · 6 comments
Assignees
Labels
api: cloudtrace Issues related to the Cloud Trace API. type: question Request for information or clarification. Not an issue.

Comments

@Zopitirik
Copy link

Hi,

If request to serviceA is being traced, I would expect the request from serviceA to serviceB should be also tracked without any other configuration.
when I tried and also read both docs and codes, there should be named httpClient to configure AddOutgoingGoogleTraceHandler docs
Was it done on purpose or is there something I missed?
Should we configure all httpClients one by one or do you have any other solution to work service wide and not need httpClient configurations?

I asked this because we have 4 project and each project has 40 services. :)

I thought to write a httpClient wrapper to send all HTTP requests on it. So I can detect that the request is traced add traceContext to header and move on. ref : #9856 (comment)

@amanda-tarafa amanda-tarafa self-assigned this Feb 22, 2023
@amanda-tarafa amanda-tarafa added type: question Request for information or clarification. Not an issue. api: cloudtrace Issues related to the Cloud Trace API. labels Feb 22, 2023
@amanda-tarafa
Copy link
Contributor

amanda-tarafa commented Feb 22, 2023

From your question I'm guessing your setup is as follows:

  • You have an application (app1) that makes requests to serviceA.
  • You have configured app1 to trace outgoing requests (with Google.Cloud.Diagnostics.*), so requests to serviceA are traced.
  • serviceA makes a request to serviceB and you expect that the configuration in app1 is enough to have the request from serviceA to serviceB be traced? Is this your question?

If I understood your question correctly then no, Google.Cloud.Diagnostics.* configured in app1 has absolutetely no control over what serviceA does. Google.Cloud.Diagnostics.* configured in app1 only makes sure that a trace context is propageted in requests from app1 to serviceA, but what serviceA does with that we have no control over, unless you configure Google.Cloud.Diagnostics.* on serviceA itself.

If my understanding is not right, then please share a minimal but complete set of projects that reproduces the behaviour you are seeing vs. the behaviour you expected.

@Zopitirik
Copy link
Author

Zopitirik commented Feb 22, 2023

Hi Amanda,

You understand right, sory for my writing skill :)
I understand your point. Let me explain without projects :) If I fail then ill create minimal projects.

app1 sends req1 -> serviceA sends req2 -> serviceB

app1 has services.AddGoogleDiagnosticsForAspNetCore() on startup.cs
serviceA has services.AddGoogleDiagnosticsForAspNetCore() on startupc.s
serviceB has services.AddGoogleDiagnosticsForAspNetCore() on startup.cs

When I click a button on app1 and send to req1 to ServiceA, trace list only shows req1 (app1 -> serviceA). Waterfall graph not shows chained request like req2.

So all project have Google.Cloud.Diagnostics.* and configured with "AddGoogleDiagnosticsForAspNetCore".

If you tell me "req2 must be listed on waterfall graph without any other configuration", means that I will create example project :)
OR

If I add a line to serviceA startup services.AddHttpClient("myHttpClient").AddOutgoingGoogleTraceHandler();
and use "myHttpClient" to send request to ServiceB, waterfall lists req2 too. This is what I wanted to see.
The question is here "should I only use myHttpClient to send request to ServiceB to see req2 on waterfall graph?"

This means; we must always configure named httpClient with AddOutgoingGoogleTraceHandler and use this to send requests at each service.

You can just say "give me the project :)"

@amanda-tarafa
Copy link
Contributor

amanda-tarafa commented Feb 22, 2023

If I add a line to serviceA startup services.AddHttpClient("myHttpClient").AddOutgoingGoogleTraceHandler();
and use "myHttpClient" to send request to ServiceB, waterfall lists req2 too. This is what I wanted to see.
The question is here "should I only use myHttpClient to send request to ServiceB to see req2 on waterfall graph?"

This means; we must always configure named httpClient with AddOutgoingGoogleTraceHandler and use this to send requests at each service.

Yes, if you want your trace to propagate (so that all requests on the chain are included on the same trace and shown on the waterfall graph) you need to confgure each relevant HttpClient with AddOutgoingGoogleTraceHandler. What happens when you don't do that is that the trace from app1 is not propagated to serviceA, so when the request reaches serviceA a new trace is created, which is also not propagated to serviceB which itself creates a new trace. You can find this 3 traces if you use HttpClients that have not been configured with AddOutgoingGoogleTraceHandler.

Note that Google.Cloud.Diagnostics.* does not require you to use named HTTP clients. The example shows named HTTP clients for clarity, but from Google.Cloud.Diagnostics.* side of things, you can just use the basic HTTP client for all your requests.

@Zopitirik
Copy link
Author

Zopitirik commented Feb 23, 2023

Ok, I understand the way you go and clear for me.
Last question for basic HTTP client.
I want to apply AddOutgoingGoogleTraceHandler to all httpClients in serviceA. This method needs IHttpClientBuilder.

AddHttpClient() returns IServiceCollection -> ref : link

AddHttpClient("") returns IHttpClientBuilder -> ref: link

Do you have a suggestion to apply this to all httpClients in serviceA?

Also IHttpClientBuilder interface has Name -> ref: link

Docs: link

@amanda-tarafa
Copy link
Contributor

You can configure the default client by adding and configuring a named client with the default name (see the Remarks section).

That means that your configuration code looks like:

services.AddHttpClient(Options.DefaultName).AddOutgoingGoogleTraceHandler();

but the code where you use the HTTP client doesn't need to request any specifically named clients.

@Zopitirik
Copy link
Author

ty, we will go on this way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: cloudtrace Issues related to the Cloud Trace API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

2 participants