> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Zero CodeAutomatic Instrumentation

> Zero-code automatic instrumentation using agents to add OpenTelemetry traces metrics and logs at runtime without source changes via bytecode manipulation monkey patching or eBPF for rapid observability

Code-based and library-based instrumentation require changing application source code: you need access to the code and knowledge of where to add instrumentation. In many real-world situations you may not have source access or permission to modify the application. In those cases, automatic (zero-code) instrumentation is often the fastest and least intrusive way to add observability.

In zero-code instrumentation, an agent injects telemetry at runtime so an application begins producing traces, metrics, and logs without any source changes. You do not need to learn the OpenTelemetry API/SDKs or modify the application to get basic observability.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/OYg0ei_WZpJtYDrJ/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Instrumentation/Zero-CodeAutomatic-Instrumentation/automatic-zero-code-instrumentation-diagram.jpg?fit=max&auto=format&n=OYg0ei_WZpJtYDrJ&q=85&s=16ae1de7b745f514e526e0694f2a51e4" alt="The image illustrates &#x22;Automatic / Zero-Code Instrumentation&#x22; with a person examining code on a computer screen and others working on a syringe-like instrument. It conveys the concept of automatic telemetry data generation without code changes." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Instrumentation/Zero-CodeAutomatic-Instrumentation/automatic-zero-code-instrumentation-diagram.jpg" />
</Frame>

What does zero-code instrumentation look like in practice? Here are two common, practical examples for JVM and Python applications.

* Java (JVM): attach the OpenTelemetry Java agent when starting the JVM:

```bash theme={null}
java -javaagent:/path/to/opentelemetry-javaagent.jar -jar myapp.jar
```

The Java agent instruments supported frameworks and libraries at class-load time by modifying bytecode. No source changes are required.

* Python: use the OpenTelemetry CLI wrapper to instrument supported libraries at runtime:

```bash theme={null}
opentelemetry-instrument python app.py
```

The CLI performs monkey-patching of common libraries (Flask, Django, Requests, etc.) so the running process emits telemetry without modifying `app.py`.

Both examples turn an existing application into a telemetry-producing source with no code edits. This makes automatic instrumentation a fast way to add observability—often in minutes.

The main advantage is speed: enable it quickly without touching the code. It's ideal for legacy apps, third-party binaries, or environments where developers cannot modify source. The trade-off is that domain-specific or business-logic spans are generally not created automatically; automatic instrumentation covers widely used frameworks and libraries but cannot infer custom business operations.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/OYg0ei_WZpJtYDrJ/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Instrumentation/Zero-CodeAutomatic-Instrumentation/pros-cons-comparison-concept-diagram.jpg?fit=max&auto=format&n=OYg0ei_WZpJtYDrJ&q=85&s=f3a57c4bcfa1c0f343c52c98330fac19" alt="The image shows a comparison of pros and cons for a concept. Pros include zero code changes and compatibility, while cons mention limitations with domain-specific operations." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Instrumentation/Zero-CodeAutomatic-Instrumentation/pros-cons-comparison-concept-diagram.jpg" />
</Frame>

How does the agent inject instrumentation without changing source code? Common techniques include:

* Monkey patching: used in dynamic languages such as Python and JavaScript. At runtime, the agent replaces or wraps library functions to call telemetry APIs.
* Bytecode manipulation: used in statically compiled runtimes such as Java and .NET. The agent modifies bytecode as classes/assemblies are loaded to insert telemetry before/after method execution.
* eBPF-based instrumentation: OpenTelemetry’s eBPF initiative observes system-level events (network, syscalls) from the kernel, providing language-agnostic and non-intrusive telemetry—useful in containerized or polyglot environments (see [https://github.com/open-telemetry/opentelemetry-ebpf](https://github.com/open-telemetry/opentelemetry-ebpf)).

Each technique has different trade-offs in terms of fidelity, overhead, and visibility into application internals.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/OYg0ei_WZpJtYDrJ/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Instrumentation/Zero-CodeAutomatic-Instrumentation/zero-code-instrumentation-techniques-diagram.jpg?fit=max&auto=format&n=OYg0ei_WZpJtYDrJ&q=85&s=7d9f55dce57b30d5f84b843c241cef57" alt="The image outlines three techniques used in zero-code instrumentation: monkey patching (Python, JavaScript), bytecode manipulation (Java, .NET), and OpenTelemetry eBPF instrumentation (OBI)." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Instrumentation/Zero-CodeAutomatic-Instrumentation/zero-code-instrumentation-techniques-diagram.jpg" />
</Frame>

When these techniques run, agents typically provide the OpenTelemetry API and SDK implementations at runtime (or hook into existing ones). That means exporters, processors, and resource configuration become available so spans, metrics, and logs can be produced and exported without touching application source code.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/OYg0ei_WZpJtYDrJ/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Instrumentation/Zero-CodeAutomatic-Instrumentation/opentelemetry-runtime-capabilities-diagram.jpg?fit=max&auto=format&n=OYg0ei_WZpJtYDrJ&q=85&s=7db057b2791ef20d1a43646298d3f4e1" alt="The image shows a diagram of injected OpenTelemetry capabilities at runtime, featuring the OpenTelemetry API and SDK." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Instrumentation/Zero-CodeAutomatic-Instrumentation/opentelemetry-runtime-capabilities-diagram.jpg" />
</Frame>

What parts of an application get instrumented automatically? Typical coverage includes:

|          Category | Typical Examples                    |
| ----------------: | ----------------------------------- |
|      HTTP clients | Requests, `http.client`, axios      |
|    Web frameworks | Flask, Django, Express, Spring Boot |
|  Database clients | SQLAlchemy, JDBC drivers            |
| Messaging systems | Kafka, RabbitMQ, AMQP libraries     |

Automatic instrumentation usually does not capture application-specific business logic—those spans must be added with code-based instrumentation if you need fine-grained, domain-specific traces.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/OYg0ei_WZpJtYDrJ/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Instrumentation/Zero-CodeAutomatic-Instrumentation/automated-instrumentation-service-categories.jpg?fit=max&auto=format&n=OYg0ei_WZpJtYDrJ&q=85&s=2c7398561bd2c11e6eda18b9018a13bc" alt="The image depicts categories of services that are instrumented automatically: HTTP Clients, Web Frameworks, Database Clients, and Messaging Systems. It notes that custom business logic requires code-based instrumentation." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Instrumentation/Zero-CodeAutomatic-Instrumentation/automated-instrumentation-service-categories.jpg" />
</Frame>

Configuration: even without source access, zero-code instrumentation still offers flexibility. Typical mechanisms include:

* Environment variables (most common)
* System properties (common for Java/.NET)
* Startup arguments (runtime customization)

Using these you can set service metadata, exporters, propagators, resource attributes, sampling, and other runtime behaviors. Example configuration options you might set via environment variables:

* Service name (so traces are grouped under a logical service in your observability backend)
* Exporter (OTLP, console, etc.)
* Propagators (W3C trace-context, B3)
* Resource attributes (environment, region, team, etc.)

Example environment variable snippets:

```bash theme={null}
# Example: set service name and OTLP exporter
OTEL_SERVICE_NAME="orders-service"
OTEL_EXPORTER_OTLP_ENDPOINT="https://otel-collector.example.com:4317"
OTEL_TRACES_EXPORTER="otlp"
OTEL_PROPAGATORS="tracecontext,baggage"
```

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/OYg0ei_WZpJtYDrJ/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Instrumentation/Zero-CodeAutomatic-Instrumentation/common-configuration-settings-graphic.jpg?fit=max&auto=format&n=OYg0ei_WZpJtYDrJ&q=85&s=92d926a84007592c4dd315c4a6b34474" alt="The image displays a graphic titled &#x22;Common Configuration Settings&#x22; with four sections labeled: Service Name, Exporter, Propagator, and Resource Attributes, each with icons and examples." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Instrumentation/Zero-CodeAutomatic-Instrumentation/common-configuration-settings-graphic.jpg" />
</Frame>

Why is zero-code instrumentation popular?

* Fast and non-invasive: enables telemetry quickly without code changes.
* Great for initial observability: provides immediate visibility into production systems.
* Low developer effort: only change how the app is started or its runtime environment.
* Configurable and extensible: environment variables and startup options let you tailor behavior.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/OYg0ei_WZpJtYDrJ/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Instrumentation/Zero-CodeAutomatic-Instrumentation/zero-code-instrumentation-benefits-diagram.jpg?fit=max&auto=format&n=OYg0ei_WZpJtYDrJ&q=85&s=61d0ee058c78e8af6aadc87c8020cfd4" alt="The image presents the advantages of zero-code instrumentation, highlighting four benefits: fast and non-invasive setup, suitability for initial observability, no developer effort required, and being configurable and extensible." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/Instrumentation/Zero-CodeAutomatic-Instrumentation/zero-code-instrumentation-benefits-diagram.jpg" />
</Frame>

<Callout icon="lightbulb" color="#1CB2FE">
  Zero-code instrumentation is an excellent first step for gaining observability quickly. Use it to get baseline telemetry, then add code-based instrumentation selectively where you need domain-specific traces or richer context.
</Callout>

That covers the essentials of zero-code automatic instrumentation. Use it to bootstrap observability, and augment with code-based instrumentation when you need custom, business-level spans.

Links and references

* OpenTelemetry: [https://opentelemetry.io/](https://opentelemetry.io/)
* OpenTelemetry eBPF project: [https://github.com/open-telemetry/opentelemetry-ebpf](https://github.com/open-telemetry/opentelemetry-ebpf)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/prep-course-opentelemetry-certified-associate-certification-otca/module/d97970ef-6201-45c2-813e-e03bc75ad77a/lesson/75aa998f-6fba-4547-9859-83ca424db6be" />
</CardGroup>
