Instrumentation: Code-based, Zero-code and Library Instrumentation: OTCA practice questions
A system is observable only when its components emit traces, metrics and logs, and the code that produces them is called instrumentation. OpenTelemetry offers two main approaches, and the docs say you can use them together.
By Ibrahim Yesilay · Published · Updated
Independent community practice, not affiliated with or endorsed by CNCF or The Linux Foundation.
What Instrumentation: Code-based, Zero-code and Library Instrumentation covers in OTCA
A system is observable only when its components emit traces, metrics and logs, and the code that produces them is called instrumentation. OpenTelemetry offers two main approaches, and the docs say you can use them together.
Zero-code instrumentation is for teams who want telemetry without editing the source, or who are just getting started. It is usually installed as an agent or something similar. Depending on the language, it injects OpenTelemetry API and SDK calls through bytecode manipulation, monkey patching or eBPF. It is available for .NET, Go, Java, JavaScript, PHP and Python. You configure it mainly through environment variables or language-specific options such as system properties, and you only need a service name to get started. Its limit is scope: it instruments the libraries an application uses, so HTTP requests and responses, database calls and message-queue calls show up, but the application's own business logic does not.
Code-based instrumentation fills that gap. You import the API, get a TracerProvider or MeterProvider, and ask it for a tracer or meter. The tracer name should identify what is being instrumented, usually the library's fully qualified name, together with a version. That name and version form the instrumentation scope, which lets backends filter telemetry by its source. A runnable service depends on both the API and the SDK and configures the SDK with exporters. It can export directly from the process or send OTLP to a Collector.
Libraries follow a stricter rule: they depend only on the API. The API is a set of abstractions with non-operational implementations, so instrumentation in a library does nothing and costs nothing until the application installs an SDK. The API also never throws and swallows exceptions, so faulty instrumentation cannot break application logic. Because errors are hidden, instrumentation should be tested, ideally with an in-memory exporter provided by the SDK.
Many libraries are covered by separate instrumentation libraries that use hooks or monkey patching. A library with built-in OpenTelemetry support is called natively instrumented, meaning it is both the instrumented library and the instrumentation library. The docs list the benefits of native instrumentation: no custom hooks to document, telemetry that is correlated with application code, and consistent conventions.
Library authors get practical modelling advice. Create spans for the logical operation, such as one database request, and leave physical network calls to the libraries that make them. Record smaller activities like serialization as span events rather than extra spans. Do not instrument a thin wrapper when OpenTelemetry already covers the underlying network calls and no convention applies; the guidance says that when in doubt, don't instrument. Under head sampling, check whether a span is recording before computing expensive attributes. Finally, follow semantic conventions for attribute names and set the schema URL so consumers know which convention version was used.
Key points
- Zero-code instrumentation covers the libraries an app uses; code-based instrumentation is needed for the app's own logic.
- Both approaches can run in the same service at the same time.
- Libraries depend only on the API, which does nothing and has no cost until an SDK is installed.
- A tracer should be named after the instrumenting library and given its version, which defines the instrumentation scope.
- Library guidance favors one span per logical operation, span events for small activities, and not instrumenting thin wrappers.
Three sample questions
13 OTCA questions on Instrumentation: Code-based, Zero-code and Library Instrumentation, 13 with explanations. How practice works
Question 1
- A.The SDK sampler drops business-logic spans by default, so only spans from libraries are ever exported
- B.Zero-code instrumentation typically instruments the libraries used, not the application's own code
- C.Business-logic spans require a Collector processor to be generated from the library spans
- D.Zero-code instrumentation only works for traces, so business logic shows up only in metrics
Correct answer: B
Sources: OpenTelemetry docs: Zero-code instrumentation, OpenTelemetry docs: Instrumentation
Question 2
- A.Each span gets its own unique scope, so the scope works as a second span ID for lookups
- B.The scope sets the sampling probability per library, so noisy libraries can be thinned out
- C.The scope replaces the resource, identifying the pod and host that produced the spans
- D.Backends can filter, group and compare telemetry by scope, e.g. by library version
Correct answer: D
Sources: OpenTelemetry docs: Instrumentation scope, OpenTelemetry docs: Metrics
Question 3
- A.The instrumented library and the instrumentation library are the same library
- B.A separate contrib package monkey-patches the library's code when the application starts
- C.An eBPF agent attaches to the library's process from outside
- D.The library bundles the OpenTelemetry SDK and exports data by itself
Correct answer: A
Sources: OpenTelemetry docs: Glossary, OpenTelemetry docs: Instrumenting libraries
Practice this topic
Focus mode keeps every question on Instrumentation: Code-based, Zero-code and Library Instrumentation until you leave it. 10 free guest answers, then a free account; no credit card.
Or open OTCA practice across all topics.
Sources
The explanation above was checked against these official documents.
- OpenTelemetry docs: Instrumentation (checked 2026-10-28)
- OpenTelemetry docs: Zero-code instrumentation (checked 2026-10-28)
- OpenTelemetry docs: Code-based instrumentation (checked 2026-10-28)
- OpenTelemetry docs: Instrumenting libraries (checked 2026-10-28)
- OpenTelemetry docs: Instrumentation scope (checked 2026-10-28)
- OpenTelemetry docs: Glossary (checked 2026-10-28)
Frequently asked questions
Why does my zero-code agent not show my business logic?
Zero-code instrumentation typically instruments libraries such as HTTP, database and messaging clients. To see your own code paths, add code-based instrumentation with the OpenTelemetry API.
Will adding the OpenTelemetry API to my library slow down users who do not use OpenTelemetry?
No. Without an SDK the API is non-operational, so the instrumentation does nothing and has no performance impact.