diff --git a/platform-includes/configuration/data-to-all-spans/android.mdx b/platform-includes/configuration/data-to-all-spans/android.mdx new file mode 100644 index 0000000000000..e875de16ed616 --- /dev/null +++ b/platform-includes/configuration/data-to-all-spans/android.mdx @@ -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 + } +} +``` \ No newline at end of file diff --git a/platform-includes/configuration/data-to-all-spans/java.mdx b/platform-includes/configuration/data-to-all-spans/java.mdx new file mode 100644 index 0000000000000..e875de16ed616 --- /dev/null +++ b/platform-includes/configuration/data-to-all-spans/java.mdx @@ -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 + } +} +``` \ No newline at end of file diff --git a/platform-includes/configuration/data-to-all-spans/java.spring-boot.mdx b/platform-includes/configuration/data-to-all-spans/java.spring-boot.mdx new file mode 100644 index 0000000000000..c02cd208afce2 --- /dev/null +++ b/platform-includes/configuration/data-to-all-spans/java.spring-boot.mdx @@ -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 + } +} +``` diff --git a/platform-includes/configuration/data-to-all-spans/java.spring.mdx b/platform-includes/configuration/data-to-all-spans/java.spring.mdx new file mode 100644 index 0000000000000..c02cd208afce2 --- /dev/null +++ b/platform-includes/configuration/data-to-all-spans/java.spring.mdx @@ -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 + } +} +``` diff --git a/platform-includes/performance/improving-data/android.mdx b/platform-includes/performance/improving-data/android.mdx index 3e668ced55f58..d540dca1bf679 100644 --- a/platform-includes/performance/improving-data/android.mdx +++ b/platform-includes/performance/improving-data/android.mdx @@ -49,3 +49,9 @@ span.setData("my-data-attribute-4", listOf("value1", "value2", "value3")) span.setData("my-data-attribute-5", listOf(42, 43, 44)) span.setData("my-data-attribute-6", listOf(true, false, true)) ``` + +### Adding Attributes to all Spans and Transactions + +To add an attribute to all spans, use the `beforeSendTransaction` callback: + + \ No newline at end of file diff --git a/platform-includes/performance/improving-data/java.mdx b/platform-includes/performance/improving-data/java.mdx index 3e668ced55f58..d540dca1bf679 100644 --- a/platform-includes/performance/improving-data/java.mdx +++ b/platform-includes/performance/improving-data/java.mdx @@ -49,3 +49,9 @@ span.setData("my-data-attribute-4", listOf("value1", "value2", "value3")) span.setData("my-data-attribute-5", listOf(42, 43, 44)) span.setData("my-data-attribute-6", listOf(true, false, true)) ``` + +### Adding Attributes to all Spans and Transactions + +To add an attribute to all spans, use the `beforeSendTransaction` callback: + + \ No newline at end of file