sentry-java: 4.0.0 Custom Instrumentation spans not working

Platform:

  • Android -> If yes, which Device API (and compileSdkVersion/targetSdkVersion/Build tools) version?
  • Java -> If yes, which Java (and sourceCompatibility/targetCompatibility) version?
  • Kotlin -> If yes, which Kotlin (and jvmTarget) version?
  • NDK -> If yes, which NDK/CMake version?
  • React-Native -> If yes, which version?
  • Timber -> If yes, which version?
  • Log4j2 -> If yes, which version?
  • Logback -> If yes, which version?
  • Spring -> If yes, which version?

IDE:

  • Android Studio -> If yes, which version?
  • IntelliJ -> If yes, which version?
  • Other -> NetBaens 12?

Build system:

  • Gradle -> If yes, which version?
  • Buck -> If yes, which version?
  • Bazel -> If yes, which version?
  • Maven -> If yes, which version?
  • Other -> If yes, which one?

Android Gradle Plugin:

  • Yes -> If yes, which version?
  • No

Sentry Android Gradle Plugin:

  • Yes -> If yes, which version?
  • No

Proguard/R8:

  • Enabled
  • Disabled

Platform installed with:

  • JCenter
  • Bintray
  • Maven Central
  • Manually

The version of the SDK: io.sentry:sentry:4.0.0


I have the following issue:

Steps to reproduce:

public List<Org> getOrgsFamaly() {        
        ITransaction transaction = Sentry.startTransaction("getOrgsFamaly()");
        transaction.setOperation("famaly");

        List<Org> result = new ArrayList<>();
        result.add(build(4, 2));
        result.add(build(2, 3));

        transaction.finish();
        return result;
}

private Org build(int childrens, int leafs){
        ISpan span = Sentry.getSpan();
       // span is always null
        if(nonNull(span)){
            ISpan innerSpan = span.startChild("famaly", "childes_"+childrens+"::leafs_"+leafs);
            Org org = new Org(childrens, leafs);
            innerSpan.finish();
            return org;
        }

        return null;
    }

Actual result:

  • span is always null

Expected result:

  • To have spans inside one transaction

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 26 (13 by maintainers)

Most upvoted comments

@sysmat just in case there was any misunderstanding here - you need to bind the transaction to the scope only once:

public static List<Org> getOrgsFamaly() {
  System.out.println("getOrgsFamaly");
  ITransaction transaction = Sentry.startTransaction("getOrgsFamaly()");
  Sentry.configureScope(scope -> scope.setTransaction(transaction));
  transaction.setOperation("famaly");

  List<Org> result = new ArrayList<>();
  result.add(build(4, 2));
  result.add(build(2, 3));

  transaction.finish();
  return result;
}

private static Org build(int childrens, int leafs) {
  ISpan span = Sentry.getSpan().startChild("famaly", "childes_" + childrens + "::leafs_" + leafs);
  Org org = new Org(childrens, leafs);
  span.finish();
  return org;
}

static class Org {
  private int childrens;
  private int leafs;

  public Org(int childrens, int leafs) {
    this.childrens = childrens;
    this.leafs = leafs;
  }
}

With this piece of code you will get a result in the UI like:

image