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

feat: Add Span.IsTransaction() #543

Merged
merged 6 commits into from Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@
- Add SentryTraceHeader and SentryBaggageHeader constants ([#538](https://github.com/getsentry/sentry-go/pull/538/))
- Add `Span.SetDynamicSamplingContext` method ([#539](https://github.com/getsentry/sentry-go/pull/539/))
- Add DSN getters ([#540](https://github.com/getsentry/sentry-go/pull/540))
- Add Span.IsTransaction() ([#543](https://github.com/getsentry/sentry-go/pull/543))

## 0.17.0

Expand Down
5 changes: 5 additions & 0 deletions tracing.go
Expand Up @@ -211,6 +211,11 @@ func (s *Span) SetTag(name, value string) {
s.Tags[name] = value
}

// Check if the given span is a transaction.
cleptric marked this conversation as resolved.
Show resolved Hide resolved
func (s *Span) IsTransaction() bool {
return s.isTransaction
}

// TODO(tracing): maybe add shortcuts to get/set transaction name. Right now the
// transaction name is in the Scope, as it has existed there historically, prior
// to tracing.
Expand Down
16 changes: 16 additions & 0 deletions tracing_test.go
Expand Up @@ -313,6 +313,22 @@ func TestStartTransaction(t *testing.T) {
}
}

func TestIsTansaction(t *testing.T) {
cleptric marked this conversation as resolved.
Show resolved Hide resolved
ctx := NewTestContext(ClientOptions{
EnableTracing: true,
})

transaction := StartTransaction(ctx, "Test Transaction")
if !transaction.IsTransaction() {
t.Fatalf("span.IsTransaction() = false, want true")
}

span := transaction.StartChild("Test Span")
if span.IsTransaction() {
t.Fatalf("span.IsTransaction() = true, want false")
}
}

// testContextKey is used to store a value in a context so that we can check
// that SDK operations on that context preserve the original context values.
type testContextKey struct{}
Expand Down