question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Http filter / enrich delegates are not invoked when service makes Grpc requests

See original GitHub issue

Bug Report

OpenTelemetry 1.2.0-beta2.1 OpenTelemetry.Instrumentation.Http 1.2.0-beta2.1

Tested on .NET5.0, looks like it will affect all runtimes.

Symptom

If a service with http instrumentation makes a Grpc request before a plain old Http request, the Filter and Enrich delegates within the HttpClientInstrumentation will not get invoked for any subsequent http requests.

This is particularly painful when dealing with Azure Isolated functions, which always makes a Grpc request on start-up, which due to this issue breaks all Http instrumentation. (You still get spans exported, you just can’t filter or enrich them).

What is the expected behavior?

Filter & Enrich methods should be invoked for all Http requests.

What is the actual behavior?

Filter & Enrich methods are not exported for any Http requests.

This is because:

The first time startRequestFetcher.TryFetch is invoked, innerFetcher is null, and so it calls PropertyFetch.FetcherForProperty which creates a TypedPropertyFetch

When the first request the application makes is a Grpc request, obj is of type Grpc.Shared.TelemetryHeaderHandler+ActivityStartData. This means the innerFetcher now always looks for Grpc ActivityStartData instances, and when any subsequent http request is invoked, TypedPropertyFetch.TryFetch fails because obj is now of type System.Net.Http.DiagnosticsHandler+ActivityStartData, so OnStartActivity exits prematurely.

Reproduce

Sample Repo - OtelTestHarness is an Azure isolated function which executes a Http request via a timer trigger every 15 seconds. The Filter and Enrich methods within Program.cs will not be executed for any of the http requests, as the isolated function SDK makes a Grpc request during start-up.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
CodeBlanchcommented, Nov 29, 2021

Thanks for the sample repo @BlakeWills! I opened a PR that I think will take care of the problem without users needing to add in AddGrpcClientInstrumentation to their tracer config.

0reactions
BlakeWillscommented, Nov 22, 2021

FYI a workaround is to set SuppressDownstreamInstrumentation:

using (Sdk.CreateTracerProviderBuilder()
	.AddSource("test-source")
	.AddGrpcClientInstrumentation(o =>
	{
		o.SuppressDownstreamInstrumentation = false;
	})
Read more comments on GitHub >

github_iconTop Results From Across the Web

gRPC interceptors on .NET
Interceptors are a gRPC concept that allows apps to interact with incoming or outgoing gRPC calls. They offer a way to enrich the...
Read more >
gRPC to REST Advanced :: Gloo Edge Docs
In this guide we will deploy a gRPC micro-service and transform its gRPC API to a REST API via Gloo Edge. To understand...
Read more >
c# - .NET 5 GRPC client call throws exception: Requesting ...
The workaround for local development is to manually set the default proxy for the HttpClient before making the gRPC call: HttpClient.
Read more >
Traffic processing :: Gloo Edge Docs
With Gloo Edge, you can configure the gateway listener along with custom Envoy filters to process the traffic that enters into and out...
Read more >
REST Swagger - Apache Camel
Configure REST producers based on a Swagger (OpenAPI) specification document delegating to a component implementing the RestProducerFactory interface.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found