@WithSpan not working with Springboot

See original GitHub issue

Describe the bug Following the documentation’s instructions: https://opentelemetry.io/docs/instrumentation/java/automatic/annotations/, I set up javaagent and was able to get span successfully, but when I use @WithSpan, no span is created

Steps to reproduce

  • Init a very simple springboot 2.7.3 application dependencies in pom.xml:
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    ...
    
    <dependency>
        <groupId>io.opentelemetry.instrumentation</groupId>
        <artifactId>opentelemetry-instrumentation-annotations</artifactId>
        <version>1.17.0-alpha</version>
    </dependency>
</dependencies>

DemoController.java:

package com.example.demo.controller;

import com.example.demo.entity.GeneralResult;
import com.example.demo.service.DemoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("demo")
public class DemoController {
    @Resource
    DemoService demoService;

    @GetMapping("/get")
    public GeneralResult getDemo() {
        Map<String, Object> map = new HashMap<>();
        map.put("randomInt", demoService.randomInt(System.currentTimeMillis()));
        return GeneralResult.success(map);
    }
}

DemoService:

package com.example.demo.service;

import io.opentelemetry.instrumentation.annotations.SpanAttribute;
import io.opentelemetry.instrumentation.annotations.WithSpan;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Random;

@Service
@Slf4j
public class DemoService {
    @WithSpan
    public Integer randomInt(@SpanAttribute long seed) {
        return new Random(seed).nextInt();
    }
}
  • Config Environment and javaagent in Intellj Idea
env: OTEL_METRICS_EXPORTER=none;OTEL_SERVICE_NAME=java-demo;OTEL_TRACES_EXPORTER=otlp
vm options: -javaagent:lib/opentelemetry-javaagent.jar
  • Start the application and then request the demo/get, and successfully collect two spans, named /demo/get and DemoController.getDemo, but missing the expected DemoService.randomInt

What did you expect to see? successfully collect /demo/get , DemoController.getDemo and DemoService.randomInt and any method with @WithSpan

What did you see instead? @WithSpan not working propertly, missing the expected span DemoService.randomInt

What version are you using?

<dependency>
    <groupId>io.opentelemetry.instrumentation</groupId>
    <artifactId>opentelemetry-instrumentation-annotations</artifactId>
    <version>1.17.0-alpha</version>
</dependency>

Environment Compiler: Eclipse Adoptium\jdk-8.0.342.7-hotspot OS: Windows10

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mateuszrzeszutekcommented, Aug 26, 2022

Ouch, looks like we missed that one link. Thanks for pointing that out! I’ll update it to the latest version.

0reactions
axiangcodingcommented, Aug 26, 2022

@trask @mateuszrzeszutek version 1.17 works! I downloaded the jar package directly from the hyperlink in the documentation (https://opentelemetry.io/docs/instrumentation/java/automatic/) and didn’t notice that the jar package was outdated. thanks again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make @WithSpan apply to Class level. #2164 - GitHub
I am in spring boot application and I have Interface A and Concrete Implementation class but Agent does not seem to pick @WithSpan...
Read more >
Opentelemetry: How to add logs to a span - Stack Overflow
I am using OpenTelemetry java auto instrumentation in my spring boot app. Is there a way to make the application logs ...
Read more >
Using Spring Cloud Sleuth
Span - Span is a single unit of work that needs to be started and stopped. Contains timing information and events and tags....
Read more >
Annotations | OpenTelemetry
Creating spans around methods with @WithSpan. To create a span corresponding to one of your method, annotate the method with @WithSpan .
Read more >
Get Current Trace ID in Spring Cloud Sleuth - Baeldung
Get started with Spring 5 and Spring Boot 2, through the Learn Spring course: ... Then they can use this to debug and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found