dependabot[bot] 3ff44fa114 Bump com.google.protobuf:protobuf-java-util from 3.22.3 to 3.22.4 in /examples/distro (#8418) 1 year ago
..
agent aeac361816 Upgrade to otel java 1.19.0 (#6757) 2 years ago
bootstrap 107201425f Improve sample distro (#6531) 2 years ago
custom 2d776af318 Auto-update OTel SDK (#7633) 2 years ago
gradle 0e15a47e93 Upgrade to gradle 8.0.2 (#7978) 2 years ago
instrumentation 0874b333cb Bump com.squareup.okhttp3:okhttp from 4.10.0 to 4.11.0 in /examples/distro (#8351) 1 year ago
smoke-tests 3ff44fa114 Bump com.google.protobuf:protobuf-java-util from 3.22.3 to 3.22.4 in /examples/distro (#8418) 1 year ago
testing aeac361816 Upgrade to otel java 1.19.0 (#6757) 2 years ago
README.md 2d7395c44b Introduce markdown lint check (#7175) 2 years ago
build.gradle 65d12109ec Bump versions.junit from 5.9.2 to 5.9.3 in /examples/distro (#8377) 1 year ago
gradle.properties cf805d87e0 Run Gradle and compile code with Java 17 (#5623) 3 years ago
gradlew 0e15a47e93 Upgrade to gradle 8.0.2 (#7978) 2 years ago
gradlew.bat 0e15a47e93 Upgrade to gradle 8.0.2 (#7978) 2 years ago
settings.gradle 107201425f Improve sample distro (#6531) 2 years ago

README.md

Distro

Introduction

This repository serves as a collection of examples of extending functionality of OpenTelemetry Java instrumentation agent. It demonstrates how to repackage the aforementioned agent adding custom functionality. For every extension point provided by OpenTelemetry Java instrumentation, this repository contains an example of its usage.

General structure

This repository has four main submodules:

  • custom contains all custom functionality, SPI and other extensions
  • agent contains the main repackaging functionality and, optionally, an entry point to the agent, if one wishes to customize that
  • instrumentation contains custom instrumentations added by vendor
  • smoke-tests contains simple tests to verify that resulting agent builds and applies correctly

Extensions examples

Instrumentation customisation

There are several options to override or customise instrumentation provided by the upstream agent. The following description follows one specific use-case:

Instrumentation X from Otel distribution creates span that I don't like and I want to change it in my vendor distro.

As an example, let us take some database client instrumentation that creates a span for database call and extracts data from db connection to provide attributes for that span.

I don't want this span at all

The easiest case. You can just pre-configure your distribution and disable given instrumentation.

I want to add/modify some attributes and their values does NOT depend on a specific db connection instance

E.g. you want to add some data from call stack as span attribute. In this case just provide your custom SpanProcessor. No need for touching instrumentation itself.

I want to add/modify some attributes and their values depend on a specific db connection instance

Write a new instrumentation which injects its own advice into the same method as the original one. Use getOrder method to ensure it is run after the original instrumentation. Now you can augment current span with new information.

See DemoServlet3Instrumentation.

I want to remove some attributes

Write custom exporter or use attribute filtering functionality in Collector.

I don't like Otel span at all. I want to significantly modify it and its lifecycle

Disable existing instrumentation. Write a new one, which injects Advice into the same (or better) method as the original instrumentation. Write your own Advice for this. Use existing Tracer directly or extend it. As you have your own Advice, you can control which Tracer you use.