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

exporter/trace: Support span link type #791

Open
mattayes opened this issue Jan 3, 2024 · 4 comments
Open

exporter/trace: Support span link type #791

mattayes opened this issue Jan 3, 2024 · 4 comments
Assignees
Labels

Comments

@mattayes
Copy link

mattayes commented Jan 3, 2024

Problem

I have a parent-child relationship between spans (e.g., processing batches of requests). I'd like to be able to use that data when consuming the Cloud Trace API (e.g., seeing parent-child relationship in Cloud Trace explorer).

While the Cloud Trace API natively supports this via the span link type, OTEL does not, so all links relationships are unspecified, leading to a worse UX.

Solutions

Having a way to both use OTEL and the span link type would make using links a lot more powerful.

One approach would be to have a magic attribute in Link.Attributes that holds the type and is popped from Attributes and added to the link in linksProtoFromLinks(). Psuedo-code:

const magicAttrType = "span_link_type"

func LinkWithType(t *sdktrace.Link, type tracepb.Span_Link_Type) {
	s.Attributes = append(s.Attributes, keyvalue.Int64(magicAttrType, int64(type))
}

func typeFromAttrs(attrs *[]attribute.KeyValue) tracepb.Span_Link_type {
	if attrs == nil {
		return tracepb.Span_Link_TYPE_UNSPECIFIED
	}
	for i, attr := range *attrs {
		if attr.Key == magicAttrType {
			t := tracepb.Span_Link_Type(attr.Value.AsInt64())
			*attrs = (*attrs)[:i+copy((*attrs)[i:], (*attrs)[i+1:])] // delete magic attr
			return t
		}
	}
	return  tracepb.Span_Link_TYPE_UNSPECIFIED
}

func linksProtoFromLinks(...) {
	...
	linkPb := &tracepb.Span_Link{
		TraceId: link.SpanContext.TraceID().String(),
		SpanId:  link.SpanContext.SpanID().String(),
		Type:    typeFromAttrs(&link.Attributes),
	}
	...
}

func CallerCode() {
	var link sdktrace.Link
	trace.LinkWithType(&link, tracepb.Span_link_Type_PARENT)
	ctx, span := tracer.Start(ctx, "my-span", sdktrace.WithLinks(link))
	...

Another approach would be to work with OTEL and have the spec support relationships directly.

@mattayes mattayes changed the title exporter/trace: Support setting span link type exporter/trace: Support span link type Jan 7, 2024
@dashpole dashpole self-assigned this Jan 8, 2024
@dashpole dashpole added enhancement New feature or request trace labels Jan 8, 2024
@aabmass
Copy link
Contributor

aabmass commented Jan 29, 2024

@dashpole do you think this is the way we'd want to implement this, vs trying to get this upstreamed?

@dashpole
Copy link
Contributor

... leading to a worse UX

@mattayes Can you share a screenshot, or something that shows how the UX is degraded with an unknown span link type?

I'm not against having a special attribute for span link type. Obviously it would be better to have it supported upstream, but that is a lot more work.

@mattayes are you using the in-process span exporter, or the collector exporter?

@mattayes
Copy link
Author

@dashpole I assumed that, if the parent-child relationship is known, the Trace Explorer UI could display the whole chain. For example, if we're using a fan-in approach, we'll see N parent traces fanning into a single child trace in the UI (e.g., part of the timing visualization). Alternatively, if I started from one of the parent traces, I'd be able to see the whole flow—including through the child trace—in the UI.

That appears to not be the case today: it looks like it'll always only show up in the Metadata & Links section. AFAICT there's no way to see the entire trace, including through links: at every link we need to navigate to the next trace. That's what I meant by "worse UX": if we could see everything at once the links would be a lot more useful.

@dashpole We're using exporter/trace, which I believe is the in-process span exporter.

@dashpole
Copy link
Contributor

@mattayes thanks. I don't think the link type impacts whether or not the link is followed in the UI. I'll share your feedback with the UI team.

Given the only impact is adding the field in the metadata & links section, i'm inclined to say we should wait for upstream to add this before changing our exporters. It seems like a custom attribute is about as useful as setting the link type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants