---
title: Code-Based Custom Instrumentation
description: >-
  Add custom spans, tags, and instrumentation to capture application-specific
  observability data using Datadog APIs and OpenTelemetry.
breadcrumbs: Docs > APM > Application Instrumentation > Code-Based Custom Instrumentation
---

# Code-Based Custom Instrumentation

## Overview{% #overview %}

Code-based custom instrumentation allows for precise monitoring of specific components in your application. It allows you to capture observability data from in-house code or complex functions that aren't captured by automatic instrumentation. Automatic instrumentation includes [Single Step Instrumentation](https://docs.datadoghq.com/tracing/trace_collection/single-step-apm) or using [Datadog tracing libraries](https://docs.datadoghq.com/tracing/trace_collection/automatic_instrumentation/dd_libraries/).

Code-based custom instrumentation involves embedding tracing code directly into your application code. This allows for the programmatic creation, modification, or deletion of traces to send to Datadog.

{% alert level="info" %}
To add custom instrumentation at specific application code locations from the Datadog UI, without code changes, see [Dynamic Instrumentation](https://docs.datadoghq.com/tracing/dynamic_instrumentation/).
{% /alert %}

## Getting started{% #getting-started %}

Before you begin, make sure you've already [installed and configured the Agent](https://docs.datadoghq.com/tracing/trace_collection/automatic_instrumentation/?tab=datadoglibraries#install-and-configure-the-agent).

Follow the relevant documentation for your custom instrumentation approach to learn more:

{% tab title="OpenTelemetry API (Recommended)" %}
Datadog tracing libraries provide an implementation of the OpenTelemetry API for instrumenting your code. This means you can maintain vendor-neutral instrumentation of all your services, while still taking advantage of Datadog's native implementation, features, and products. You can configure it to generate Datadog-style spans and traces to be processed by the Datadog tracing library for your language, and send those to Datadog.

- [Java](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/server-side/?api_type=otel_api&prog_lang=java)
- [Python](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/server-side/?api_type=otel_api&prog_lang=python)
- [Ruby](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/server-side/?api_type=otel_api&prog_lang=ruby)
- [go](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/server-side/?api_type=otel_api&prog_lang=go)
- [Node.js](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/server-side/?api_type=otel_api&prog_lang=node_js)
- [PHP](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/server-side/?api_type=otel_api&prog_lang=php)
- [.Net](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/server-side/?api_type=otel_api&prog_lang=dot_net)
- [iOS](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/client-side/ios/)
- [Android](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/client-side/android/)
- [Rust](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/server-side/?api_type=otel_api&prog_lang=rust)
- [Elixir](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/server-side/?api_type=otel_api&prog_lang=elixir)

{% /tab %}

{% tab title="Datadog API" %}
Use the Datadog API to add custom instrumentation that allows you to programmatically create, modify, or delete traces to send to Datadog. This is useful for tracing in-house code not captured by automatic instrumentation, removing unwanted spans from traces, and for providing deeper visibility and context into spans, including adding span tags.

- [Java](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/server-side/?api_type=dd_api&prog_lang=java)
- [Python](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/server-side/?api_type=dd_api&prog_lang=python)
- [Ruby](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/server-side/?api_type=dd_api&prog_lang=ruby)
- [go](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/server-side/?api_type=dd_api&prog_lang=go)
- [Node.js](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/server-side/?api_type=dd_api&prog_lang=node_js)
- [PHP](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/server-side/?api_type=dd_api&prog_lang=php)
- [C++](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/server-side/?api_type=dd_api&prog_lang=cpp)
- [.Net](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/server-side/?api_type=dd_api&prog_lang=dot_net)
- [Android](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/client-side/android/)

{% /tab %}

{% tab title="OpenTracing (Legacy)" %}
If [OpenTelemetry](https://docs.datadoghq.com/tracing/trace_collection/otel_instrumentation/) or [`ddtrace`](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/) custom instrumentation doesn't work for you, each of the supported languages also has support for sending [OpenTracing](https://opentracing.io/docs/) data to Datadog. OpenTracing is archived and the project is unsupported.

- [Java](opentracing/java)
- [Python](opentracing/python)
- [Node.js](opentracing/nodejs)
- [Ruby](opentracing/ruby)
- [.Net](opentracing/dotnet)
- [PHP](opentracing/php)
- [Android](opentracing/android)

{% /tab %}

## Further reading{% #further-reading %}

- [Instrument a custom method to get deep visibility into your business logic](https://docs.datadoghq.com/tracing/guide/instrument_custom_method)
- [Connect your Logs and Traces together](https://docs.datadoghq.com/tracing/connect_logs_and_traces)
- [Explore your services, resources, and traces](https://docs.datadoghq.com/tracing/visualization/)
- [Learn More about Datadog and the OpenTelemetry initiative](https://www.datadoghq.com/blog/opentelemetry-instrumentation/)
