opentracing-contrib / java-spring-web

OpenTracing Spring Web instrumentation
Apache License 2.0
107 stars 59 forks source link

Disable reporting spans for actuator endpoints #117

Closed mariusgiger closed 5 years ago

mariusgiger commented 5 years ago

Hi guys,

Reposting this here.

When using Opentracing with Jaeger for Spring Cloud Gateway with actuator endpoints enabled (e.g. /actuator/health for K8s readiness probe), all calls to the actuator endpoints produce a span. Is there a way to disable this behaviour?

Config:

        <dependency>
            <groupId>io.opentracing.contrib</groupId>
            <artifactId>opentracing-spring-jaeger-cloud-starter</artifactId>
            <version>2.0.0</version>
        </dependency>

        <dependency>
            <groupId>io.opentracing.contrib</groupId>
            <artifactId>opentracing-spring-cloud-starter</artifactId>
            <version>0.3.2</version>
        </dependency>

Cheers, Marius

pavolloffay commented 5 years ago

I think this should not happen, the helthcheck probes should not be traced.

@ask4gilles could you please comment on this one? It will also transfer it to web repository.

geoand commented 5 years ago

Endpoints can be manually excluded as well, see: https://github.com/opentracing-contrib/java-spring-web/blob/master/opentracing-spring-web-starter/src/test/resources/application-test.yml#L22

But definitely the actuator endpoints should not be taken into account

mariusgiger commented 5 years ago

Thanks @pavolloffay and @geoand for the replies.

Per default, the actuator health endpoint is already ignored in the skip pattern, which is fine. However, the queries for the healthiness of a database (e.g. Mysql or Mongo) produce a span, which are invoked as part of the request to /actuator/health.

spans
geoand commented 5 years ago

@mariusgiger do you know which URLs are used for querying the healthiness of the database?

mariusgiger commented 5 years ago

@geoand these spans get produced when calling /actuator/health.

geoand commented 5 years ago

OK, thanks.

@ask4gilles any idea off the top of your head?

ask4gilles commented 5 years ago

Hi @mariusgiger @geoand and @pavolloffay

All actuator endpoints are skipped by default.

Per default, the actuator health endpoint is already ignored in the skip pattern, which is fine. However, the queries for the healthiness of a database (e.g. Mysql or Mongo) produce a span, which are invoked as part of the request to /actuator/health.

From what I understand from the above, this could be caused by the underlying select queries targeting the database(s) in the health actuator itself. I think you could verify it easily by either disabling the DB health check inside the actuator (management.health.db.enabled=false) or disabling the SQL tracing. If this is the issue, the sanity SQL query should probably be excluded from the SQL tracing.

If this does not solve your issue, can you please provide a minimal sample project in order to reproduce?

(BTW, this one https://github.com/opentracing-contrib/java-spring-jaeger/issues/63#issue-494612213 can be closed)

mariusgiger commented 5 years ago

Hi @ask4gilles,

Indeed, there are no more spans if the healthcheck for the database is disabled.

i.e. in my case:

management:
  health:
    db:
      enabled: false
    mongo:
      enabled: false

Most probably this also happens for other dependencies for healthchecks that support tracing.

Is it possible to disable tracing for a package resp. set of classes? If that is the case, either the concrete classes could be disabled (e.g. DataSourceHealthIndicator) or the base classes (e.g. AbstractHealthIndicator and AbstractReactiveHealthIndicator) or the whole package org.springframework.boot.actuate.

ask4gilles commented 5 years ago

@mariusgiger thanks for the feedback. If you want to keep your DB health checks and avoid them to be traced, you could:

  1. If you are not interested in JDBC tracing: opentracing.spring.cloud.jdbc.enabled=false
  2. If you want to keep the JDBC tracing but exclude the health query, add it to this property opentracing.spring.cloud.jdbc.ignoreStatements

I don't see the equivalent properties for Mongo DB in the opentracing-spring-cloud-mongo-starter, but apparently there is also a way, see here: https://github.com/opentracing-contrib/java-mongo-driver#exclude-commands-from-tracing

Regarding the other types of health checks in the link and a possible global exclusion for them I don't think it's foreseen but I may be wrong here (@pavolloffay @geoand ?) I think that it would be more on case by case basis.

To summarize, this is not something related to the tracing of the actuators endpoints by themselves (and the title of this issue should be modified). This is also not related to this repo but to starters provided by opentracing-spring-cloud. So it could be moved there as an enhancement request.

geoand commented 5 years ago

Thanks for checking @ask4gilles!

mariusgiger commented 5 years ago

Thank you @ask4gilles for the response! This resolves the issue for me.

ask4gilles commented 5 years ago

@mariusgiger Awesome, glad it helped!

ask4gilles commented 5 years ago

@geoand this one can be closed 😉

geoand commented 5 years ago

:+1:

ahmedju commented 2 years ago

Please any update for this issue ?

EricBuist commented 1 year ago

The actuator/health endpoint is traced even without a DB, and I cannot figure out how to turn this off. Looking at generated span, this is coming from io.opentelemetry.spring-webmvc-6.0. I never imported that dependency, I searched and cannot find any clue how to configure that. Any idea?