open-telemetry / opentelemetry-java-instrumentation

OpenTelemetry auto-instrumentation and instrumentation libraries for Java
https://opentelemetry.io
Apache License 2.0
1.9k stars 828 forks source link

Tracer Bean not created #7957

Closed amexboy closed 1 year ago

amexboy commented 1 year ago

Describe the bug I am trying to use the spring-boot-starter in my very basic demo project. I am trying to use the Tracer bean by auto-wiring it in my controller. My gradle build script is aa

Steps to reproduce My gradle build script looks like this

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.0.3'
    id 'io.spring.dependency-management' version '1.1.0'
}

group = 'de.kreuzwerker'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation("io.opentelemetry.instrumentation:opentelemetry-jaeger-spring-boot-starter:1.21.0-alpha")
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

import io.opentelemetry.api.trace.Tracer;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("/test")
@AllArgsConstructor
public class TestController {
   private final Tracer tracer;
}

What did you expect to see? I expect a Tracer bean to be available as noted here

What did you see instead? Spring complains that there is no such bean

What version are you using? 1.21.0-alpha

Environment Compiler: (e.g., "Zullu 17") OS: (e.g., "Mac Ventura 13")

** Additional Context

For enabling auto-configuration in spring-boot 3, I had to copy the spring.factories file into my repository as described here

laurit commented 1 year ago

@amexboy Thanks for reporting. The documentation is outdated, you can use either the OpenTelemetry or TracerProvider bean to get the tracer.

amexboy commented 1 year ago

@laurit Thanks for the reply,

I figured that the Tracer bean didn't exist anymore. I will create a PR to update the documentation.

In the meantime. I couldn't also get the OpenTelemetry bean. After a little bit of investigation, I noticed that Spring Boot 3 removed for support of spring.factories file which was deprecated in 2.7 (I believe).

I can create a PR to add Spring 3 support. To maintain backward compatibility (which I suppose is desired), I will keep the spring.factories file as is and create the Spring Boot 3 version of the file (META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports).

What do you think?

laurit commented 1 year ago

I believe the plan was to have separate starters for spring-boot 2 and spring-boot 3 but before that happens doing what @amexboy described feels like a good idea. @mateuszrzeszutek is this ok with you?

mateuszrzeszutek commented 1 year ago

I think it's a good idea even if we end up having separate starters for v2 and v3 - in that case it'll allow us to reuse even more code between the two versions.

amexboy commented 1 year ago

Fun and fantastic, I will follow up with a PR. I'll also make sure to update the documentation 👍

On Wed, Mar 8, 2023, 15:56 Mateusz Rzeszutek @.***> wrote:

I think it's a good idea even if we end up having separate starters for v2 and v3 - in that case it'll allow us to reuse even more code between the two versions.

— Reply to this email directly, view it on GitHub https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/7957#issuecomment-1460285392, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABX63LQQGSINMJMJ4LMYBJLW3CMYRANCNFSM6AAAAAAVNUERSE . You are receiving this because you were mentioned.Message ID: <open-telemetry/opentelemetry-java-instrumentation/issues/7957/1460285392@ github.com>