-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Feat/java add data to all spans #12483
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5420d74
document how to attach data to all transactions and its spans
lbloder 5288572
Merge branch 'master' into feat/java-add-data-to-all-spans
lbloder 5ec701a
fix import statement
lbloder 7921497
fix kotlin samples, use setData on trace
lbloder 9942335
fix code samples
lbloder 22e67f7
Merge branch 'master' into feat/java-add-data-to-all-spans
adinauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
platform-includes/configuration/data-to-all-spans/android.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
```java | ||
Sentry.init(options -> { | ||
options.setBeforeSendTransaction((transaction, hint) -> { | ||
|
||
// set the attribute on the root span | ||
if (transaction.getContexts().getTrace() == null) { | ||
SpanContext spanContext = new SpanContext("op"); | ||
transaction.getContexts().setTrace(spanContext); | ||
} | ||
transaction.getContexts().getTrace().setData("myAttribute", "myValue"); | ||
|
||
// and on all child spans | ||
transaction.getSpans().forEach(span -> { | ||
if (span.getData() == null) { | ||
span.setData(new HashMap<>()); | ||
} | ||
span.getData().put("myAttribute", "myValue"); | ||
}); | ||
|
||
return transaction; | ||
}); | ||
}); | ||
``` | ||
```kotlin | ||
Sentry.init { options -> | ||
options.setBeforeSendTransaction { transaction, hint -> | ||
|
||
// set the attribute on the root span | ||
if (transaction.contexts.trace == null) { | ||
transaction.contexts.setTrace(SpanContext("op")) | ||
} | ||
transaction.contexts.trace?.setData("myAttribute", "myValue") | ||
|
||
// and on all child spans | ||
transaction.spans.forEach { span -> | ||
if (span.data == null) { | ||
span.data = HashMap() | ||
} | ||
span.data?.set("myAttribute", "myValue") | ||
} | ||
|
||
transaction | ||
} | ||
} | ||
``` |
45 changes: 45 additions & 0 deletions
45
platform-includes/configuration/data-to-all-spans/java.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
```java | ||
Sentry.init(options -> { | ||
options.setBeforeSendTransaction((transaction, hint) -> { | ||
|
||
// set the attribute on the root span | ||
if (transaction.getContexts().getTrace() == null) { | ||
SpanContext spanContext = new SpanContext("op"); | ||
transaction.getContexts().setTrace(spanContext); | ||
} | ||
transaction.getContexts().getTrace().setData("myAttribute", "myValue"); | ||
|
||
// and on all child spans | ||
transaction.getSpans().forEach(span -> { | ||
if (span.getData() == null) { | ||
span.setData(new HashMap<>()); | ||
} | ||
span.getData().put("myAttribute", "myValue"); | ||
}); | ||
|
||
return transaction; | ||
}); | ||
}); | ||
``` | ||
```kotlin | ||
Sentry.init { options -> | ||
options.setBeforeSendTransaction { transaction, hint -> | ||
|
||
// set the attribute on the root span | ||
if (transaction.contexts.trace == null) { | ||
transaction.contexts.setTrace(SpanContext("op")) | ||
} | ||
transaction.contexts.trace?.setData("myAttribute", "myValue") | ||
|
||
// and on all child spans | ||
transaction.spans.forEach { span -> | ||
if (span.data == null) { | ||
span.data = HashMap() | ||
} | ||
span.data?.set("myAttribute", "myValue") | ||
} | ||
|
||
transaction | ||
} | ||
} | ||
``` |
59 changes: 59 additions & 0 deletions
59
platform-includes/configuration/data-to-all-spans/java.spring-boot.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
```java | ||
import io.sentry.protocol.SentryTransaction; | ||
import io.sentry.SentryOptions; | ||
import io.sentry.Hint; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class CustomBeforeSendTransactionCallback implements SentryOptions.BeforeSendTransactionCallback { | ||
@Override | ||
public SentryTransaction execute(SentryTransaction transaction, Hint hint) { | ||
|
||
// set the attribute on the root span | ||
if (transaction.getContexts().getTrace() == null) { | ||
SpanContext spanContext = new SpanContext("op"); | ||
transaction.getContexts().setTrace(spanContext); | ||
} | ||
transaction.getContexts().getTrace().setData("myAttribute", "myValue"); | ||
|
||
// and on all child spans | ||
transaction.getSpans().forEach(span -> { | ||
if (span.getData() == null) { | ||
span.setData(new HashMap<>()); | ||
} | ||
span.getData().put("myAttribute", "myValue"); | ||
}); | ||
|
||
return transaction; | ||
} | ||
} | ||
``` | ||
|
||
```kotlin | ||
import io.sentry.protocol.SentryTransaction | ||
import io.sentry.SentryOptions | ||
import io.sentry.Hint | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class CustomBeforeSendTransactionCallback : SentryOptions.BeforeSendTransactionCallback { | ||
override fun execute(transaction: SentryTransaction, hint: Hint): SentryTransaction? { | ||
|
||
// set the attribute on the root span | ||
if (transaction.contexts.trace == null) { | ||
transaction.contexts.setTrace(SpanContext("op")) | ||
} | ||
transaction.contexts.trace?.setData("myAttribute", "myValue") | ||
|
||
// and on all child spans | ||
transaction.spans.forEach { span -> | ||
if (span.data == null) { | ||
span.data = HashMap() | ||
} | ||
span.data?.set("myAttribute", "myValue") | ||
} | ||
|
||
transaction | ||
} | ||
} | ||
``` |
59 changes: 59 additions & 0 deletions
59
platform-includes/configuration/data-to-all-spans/java.spring.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
```java | ||
import io.sentry.protocol.SentryTransaction; | ||
import io.sentry.SentryOptions; | ||
import io.sentry.Hint; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class CustomBeforeSendTransactionCallback implements SentryOptions.BeforeSendTransactionCallback { | ||
@Override | ||
public SentryTransaction execute(SentryTransaction transaction, Hint hint) { | ||
|
||
// set the attribute on the root span | ||
if (transaction.getContexts().getTrace() == null) { | ||
SpanContext spanContext = new SpanContext("op"); | ||
transaction.getContexts().setTrace(spanContext); | ||
} | ||
transaction.getContexts().getTrace().setData("myAttribute", "myValue"); | ||
|
||
// and on all child spans | ||
transaction.getSpans().forEach(span -> { | ||
if (span.getData() == null) { | ||
span.setData(new HashMap<>()); | ||
} | ||
span.getData().put("myAttribute", "myValue"); | ||
}); | ||
|
||
return transaction; | ||
} | ||
} | ||
``` | ||
|
||
```kotlin | ||
import io.sentry.protocol.SentryTransaction | ||
import io.sentry.SentryOptions | ||
import io.sentry.Hint | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class CustomBeforeSendTransactionCallback : SentryOptions.BeforeSendTransactionCallback { | ||
override fun execute(transaction: SentryTransaction, hint: Hint): SentryTransaction? { | ||
|
||
// set the attribute on the root span | ||
if (transaction.contexts.trace == null) { | ||
transaction.contexts.setTrace(SpanContext("op")) | ||
} | ||
transaction.contexts.trace?.setData("myAttribute", "myValue") | ||
|
||
// and on all child spans | ||
transaction.spans.forEach { span -> | ||
if (span.data == null) { | ||
span.data = HashMap() | ||
} | ||
span.data?.set("myAttribute", "myValue") | ||
} | ||
|
||
transaction | ||
} | ||
} | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.