Skip to content

Conversation

@stellarhuman
Copy link
Contributor

Description

Added a way to directly get the spanId, from the span that is created.

}

func (s *Span) GetSpanId() string {
return s.Span.SpanContext().SpanID().String()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we expect this value to be not null everytime or do need to something like

if (s.Span.SpanContext().SpanID().HasSpanID()) {
   s.Span.SpanContext().SpanID().String()
 }
 return ""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idts, if a span doest exist, you should always be able to call this method

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be fine. String's null value is empty string in golang. As long as it returns a string, we dont have to check here explicitly

func TestGetSpanID(t *testing.T) {
_, s, _ := StartSpan(context.Background(), "test_span", &sdk.SpanOptions{})
spanId := s.GetSpanId()
if len(spanId) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use assertions instead. ex: assert.Equal(t, 8, SpanIDNoOfBytes)

@varkey98
Copy link
Contributor

Do we really need this change here in goagent? We can simply do this in TPA if this is the route you want to go

	spanCtx := trace.SpanContextFromContext(ctx)
	if spanCtx.HasTraceID() {
		fmt.Println(spanCtx.TraceID().String())
	}

	if spanCtx.HasSpanID() {
		fmt.Println(spanCtx.SpanID().String())
	}

Adding it here is not really required imo

@thugrock7
Copy link
Contributor

Yes, functionally we can get this done using trace.SpanContextFromContext(ctx) as well, but thinking about this logically , as span ID is property of span, I simply want to do something like GetSpanID() on span to fetch this ID rather than knowing internals to call spanContext ourselves and get this done where ever span ID is required .

@varkey98
Copy link
Contributor

Yes, functionally we can get this done using trace.SpanContextFromContext(ctx) as well, but thinking about this logically , as span ID is property of span, I simply want to do something like GetSpanID() on span to fetch this ID rather than knowing internals to call spanContext ourselves and get this done where ever span ID is required .

Fair enough, but I'm not sure which is better

@thugrock7
Copy link
Contributor

your inputs here @ryanericson ?

@ryanericson
Copy link
Collaborator

Yes, functionally we can get this done using trace.SpanContextFromContext(ctx) as well, but thinking about this logically , as span ID is property of span, I simply want to do something like GetSpanID() on span to fetch this ID rather than knowing internals to call spanContext ourselves and get this done where ever span ID is required .

Fair enough, but I'm not sure which is better

Ah I see what @varkey98 found which is kind of equivalent. But I agree with @thugrock7, just exposing it in our SDK is cleaner and I don't see any harm.

@varkey98 varkey98 changed the title Get span feat: Update span interface to add a new function which will return span id Feb 15, 2025
Copy link
Contributor

@varkey98 varkey98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@codecov
Copy link

codecov bot commented Feb 17, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@9789c3a). Learn more about missing BASE report.
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
sdk/internal/mock/span.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #245   +/-   ##
=======================================
  Coverage        ?   61.16%           
=======================================
  Files           ?       59           
  Lines           ?     2688           
  Branches        ?        0           
=======================================
  Hits            ?     1644           
  Misses          ?      964           
  Partials        ?       80           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@thugrock7 thugrock7 merged commit 0f0b04d into hypertrace:main Feb 17, 2025
4 of 6 checks passed
@thugrock7
Copy link
Contributor

Merging this, as @stellarhuman needs to use these changes on TPA side PR and want this PR to be included in this month release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants