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

wrap produder config support customize trace option #6579

Open
ThunderRussell opened this issue Jan 9, 2025 · 3 comments
Open

wrap produder config support customize trace option #6579

ThunderRussell opened this issue Jan 9, 2025 · 3 comments
Labels
area: propagators Related to the propagators module enhancement New feature or request

Comments

@ThunderRussell
Copy link

ThunderRussell commented Jan 9, 2025

Problem Statement

in my case, we support add some customize trace spanStartOption within producer: like this

type config struct {
	TracerProvider trace.TracerProvider
	Propagators    propagation.TextMapPropagator
	Tracer trace.Tracer
        SpanStartOptions []trace.SpanStartOption // add span start options
}

func startProducerSpan(cfg config, version sarama.KafkaVersion, msg *sarama.ProducerMessage) trace.Span {
	// If there's a span context in the message, use that as the parent context.
	carrier := NewProducerMessageCarrier(msg)
	ctx := cfg.Propagators.Extract(context.Background(), carrier)

	// Create a span.
	attrs := []attribute.KeyValue{
		semconv.MessagingSystem("kafka"),
		semconv.MessagingDestinationKindTopic,
		semconv.MessagingDestinationName(msg.Topic),
		semconv.MessagingMessagePayloadSizeBytes(msgPayloadSize(msg, version)),
		semconv.MessagingOperationPublish,
	}
        //  add users customize trace option
	opts :=append(cfg.SpanStartOptions , []trace.SpanStartOption{
		trace.WithAttributes(attrs...),
		trace.WithSpanKind(trace.SpanKindProducer),
	}...)
	ctx, span := cfg.Tracer.Start(ctx, fmt.Sprintf("%s publish", msg.Topic), opts...)

	if version.IsAtLeast(sarama.V0_11_0_0) {
		// Inject current span context, so consumers can use it to propagate span.
		cfg.Propagators.Inject(ctx, carrier)
	}

	return span
}
@ThunderRussell ThunderRussell added area: propagators Related to the propagators module enhancement New feature or request labels Jan 9, 2025
@dmathieu
Copy link
Member

dmathieu commented Jan 9, 2025

Hi,

Your question/requests is a bit unclear here. Could you try to explain a bit more what you're trying to achieve?

@ThunderRussell
Copy link
Author

Hi,
in my case, our company apm topology depends trace span with specific attributes, such as<"mq.topic", "xxx">,
i hope support to set SpanStartOptions config while otelsarama.WrapAsyncProducer

@dmathieu
Copy link
Member

dmathieu commented Jan 9, 2025

otelsarama isn't hosted on this repository anymore. It's now at https://github.com/dnwe/otelsarama

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: propagators Related to the propagators module enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants