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

[WIP] fix console samples #3979

Draft
wants to merge 13 commits into
base: feat/update-otel-sample-readme
Choose a base branch
from

Conversation

lbloder
Copy link
Collaborator

@lbloder lbloder commented Dec 10, 2024

📜 Description

Fixes the sentry console samples

💡 Motivation and Context

The sentry-samples-console-opentelemetry-noagent sample did not produce any spans.

💚 How did you test it?

📝 Checklist

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

Copy link
Contributor

github-actions bot commented Dec 10, 2024

Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

- [WIP] fix console samples ([#3979](https://github.com/getsentry/sentry-java/pull/3979))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description.

Generated by 🚫 dangerJS against 4eed72a

Copy link
Contributor

github-actions bot commented Dec 10, 2024

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 332.24 ms 336.88 ms 4.63 ms
Size 1.65 MiB 2.31 MiB 677.51 KiB

Previous results on branch: fix/fix-console-samples

Startup times

Revision Plain With Sentry Diff
42a4b98 419.52 ms 468.80 ms 49.27 ms
6ebd7bb 415.76 ms 489.13 ms 73.36 ms
d035e4a 323.87 ms 361.86 ms 37.99 ms
15316ed 429.28 ms 439.04 ms 9.76 ms
8902d25 383.02 ms 387.58 ms 4.56 ms
617e26e 466.04 ms 481.19 ms 15.15 ms

App size

Revision Plain With Sentry Diff
42a4b98 1.65 MiB 2.31 MiB 676.08 KiB
6ebd7bb 1.65 MiB 2.31 MiB 677.56 KiB
d035e4a 1.65 MiB 2.31 MiB 676.08 KiB
15316ed 1.65 MiB 2.31 MiB 676.08 KiB
8902d25 1.65 MiB 2.31 MiB 676.08 KiB
617e26e 1.65 MiB 2.31 MiB 677.57 KiB

Comment on lines +159 to +161
final TransactionOptions options = new TransactionOptions();
options.setBindToScope(true);
ITransaction transaction = Sentry.startTransaction("transaction name", "op", options);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Binding the transaction to scope is required here for the sample to work as expected as later in the code we have a line Sentry.captureMessage("this message is connected to the outerSpan"); which only works as described if the transaction is on the scope IIRC.

@@ -86,10 +87,10 @@ public static void main(String[] args) throws InterruptedException {
options.setTracesSampler(
context -> {
// only 10% of transactions with "/product" prefix will be collected
if (!context.getTransactionContext().getName().startsWith("/products")) {
if (context.getTransactionContext().getName().startsWith("/products")) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes the code do what the comment says :)

return 0.1;
} else {
return 0.5;
return 1.0;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

set to 1.0 for all transactions except for /products to make it easier for people trying this sample


public class Main {

public static void main(String[] args) throws InterruptedException {
final OpenTelemetrySdk sdk =
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

AutoConfiguredOpentelemetry is needed to initialize spi provided classes.

We can make this a little simpler by using setResultAsGlobal() on the builder:

    AutoConfiguredOpenTelemetrySdk.builder()
      .setResultAsGlobal()
      .addPropertiesSupplier(
        () -> {
          final Map<String, String> properties = new HashMap<>();
          properties.put("otel.logs.exporter", "none");
          properties.put("otel.metrics.exporter", "none");
          properties.put("otel.traces.exporter", "none");
          return properties;
        })
      .build();

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.

2 participants