All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.misk.cloud.gcp.tracing.TracingLoggingEnhancer.kt Maven / Gradle / Ivy

There is a newer version: 2024.09.17.200749-4708422
Show newest version
package misk.cloud.gcp.tracing

import com.google.cloud.logging.LogEntry
import com.google.cloud.logging.LoggingEnhancer
import io.opentracing.Tracer
import io.opentracing.util.GlobalTracer

/**
 * Add this enhancer to your project's Logback configuration to add trace ids to logs generated by
 * GCP's LoggingAppender
 */
class TracingLoggingEnhancer : LoggingEnhancer {
  override fun enhanceLogEntry(builder: LogEntry.Builder) {
    enhanceLogEntry(GlobalTracer.get(), builder)
  }

  fun enhanceLogEntry(tracer: Tracer, builder: LogEntry.Builder) {
    if (tracer.activeSpan().context().toTraceId().isNotEmpty()) {
      builder.addLabel(
        "appengine.googleapis.com/trace_id",
        tracer.activeSpan().context().toTraceId()
      )
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy