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

[jaeger-v2] Dangerous use of tracer in plugin/storage/grpc/factory.go #5971

Open
yurishkuro opened this issue Sep 11, 2024 · 1 comment · May be fixed by #5979
Open

[jaeger-v2] Dangerous use of tracer in plugin/storage/grpc/factory.go #5971

yurishkuro opened this issue Sep 11, 2024 · 1 comment · May be fixed by #5979
Labels
area/otel area/storage bug help wanted Features that maintainers are willing to accept but do not have cycles to implement

Comments

@yurishkuro
Copy link
Member

yurishkuro commented Sep 11, 2024

The factory is passed a tracer that it then passes to OTEL's ToClientConn() function, which automatically adds tracing instrumentation to gRPC connection. That means we may start generating new traces as we're trying to save spans to storage, thus causing an infinite loop of trace generation. The write path must always be devoid of tracing (or use very low sampling rate) to avoid this.

Related upstream issue open-telemetry/opentelemetry-collector#10663

@yurishkuro yurishkuro added the help wanted Features that maintainers are willing to accept but do not have cycles to implement label Sep 11, 2024
ldlb9527 added a commit to ldlb9527/jaeger that referenced this issue Sep 12, 2024
ldlb9527 added a commit to ldlb9527/jaeger that referenced this issue Sep 12, 2024
@ldlb9527 ldlb9527 linked a pull request Sep 12, 2024 that will close this issue
ldlb9527 added a commit to ldlb9527/jaeger that referenced this issue Sep 12, 2024
ldlb9527 added a commit to ldlb9527/jaeger that referenced this issue Sep 18, 2024
ldlb9527 added a commit to ldlb9527/jaeger that referenced this issue Sep 18, 2024
ldlb9527 added a commit to ldlb9527/jaeger that referenced this issue Sep 18, 2024
ldlb9527 added a commit to ldlb9527/jaeger that referenced this issue Sep 24, 2024
ldlb9527 added a commit to ldlb9527/jaeger that referenced this issue Sep 24, 2024
ldlb9527 added a commit to ldlb9527/jaeger that referenced this issue Sep 24, 2024
Copy link

dosubot bot commented Sep 26, 2024

To prevent the infinite loop of trace generation caused by the tracer in plugin/storage/grpc/factory.go in Jaeger v2, you need to ensure that the tracer used for gRPC communication does not generate traces for its own operations. This can be achieved by using a TracerProvider that is configured to ignore certain operations or by using a SpanProcessor that filters out these traces.

Here is an example of how you can modify the newRemoteStorage function to achieve this:

func (f *Factory) newRemoteStorage(telset component.TelemetrySettings, newClient newClientFn) (*ClientPluginServices, error) {
    c := f.configV2
    // Create a new TracerProvider that excludes gRPC operations
    tracerProvider := otel.GetTracerProvider()
    // Add a resource to the TracerProvider to identify the gRPC client
    resource := resource.NewWithAttributes(
        semconv.SchemaURL,
        semconv.ServiceNameKey.String("grpc-client"),
    )
    tracerProvider = sdktrace.NewTracerProvider(
        sdktrace.WithResource(resource),
        sdktrace.WithSampler(sdktrace.ParentBased(sdktrace.NeverSample())),
    )

    opts := []grpc.DialOption{
        grpc.WithStatsHandler(otelgrpc.NewClientHandler(otelgrpc.WithTracerProvider(tracerProvider))),
    }
    if c.Auth != nil {
        return nil, fmt.Errorf("authenticator is not supported")
    }

    tenancyMgr := tenancy.NewManager(&c.Tenancy)
    if tenancyMgr.Enabled {
        opts = append(opts, grpc.WithUnaryInterceptor(tenancy.NewClientUnaryInterceptor(tenancyMgr)))
        opts = append(opts, grpc.WithStreamInterceptor(tenancy.NewClientStreamInterceptor(tenancyMgr)))
    }

    remoteConn, err := newClient(opts...)
    if err != nil {
        return nil, fmt.Errorf("error creating remote storage client: %w", err)
    }
    f.remoteConn = remoteConn
    grpcClient := shared.NewGRPCClient(remoteConn)
    return &ClientPluginServices{
        PluginServices: shared.PluginServices{
            Store:               grpcClient,
            ArchiveStore:        grpcClient,
            StreamingSpanWriter: grpcClient,
        },
        Capabilities: grpcClient,
    }, nil
}

In this example, a new TracerProvider is created with a NeverSample sampler, which effectively disables tracing for the gRPC client operations. This prevents the infinite loop of trace generation [1].

To continue talking to Dosu, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/otel area/storage bug help wanted Features that maintainers are willing to accept but do not have cycles to implement
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

1 participant