# 📦 New Package: Automatic OpenTelemetry Instrumentation for MCP

**URL:** <https://community.dynatrace.com/t/new-package-automatic-opentelemetry-instrumentation-for-mcp/52777>\
**Category:** Dynatrace Tips\
**Tags:** opentelemetry, mcp-server, tips-and-tricks\
**Created:** [August 2, 2025, 7:41pm UTC](https://community.dynatrace.com/t/new-package-automatic-opentelemetry-instrumentation-for-mcp/52777 "2025-08-02T19:41:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![theharithsa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/theharithsa/32/16236_2.png) [@theharithsa](https://community.dynatrace.com/u/theharithsa)\
**Post date:** [August 2, 2025, 7:41pm UTC](https://community.dynatrace.com/t/new-package-automatic-opentelemetry-instrumentation-for-mcp/52777/1 "2025-08-02T19:41:36Z")

</div>

I’ve just published **opentelemetry-instrumentation-mcp** , a (v1.0.0) package that makes it effortless to add observability to Model Context Protocol (MCP) applications.

**Why it matters:**  
This package automatically instruments every MCP tool call with a span and exports those spans via OTLP to Dynatrace. No more boilerplate around tracer.startSpan – you get built‑in OpenTelemetry setup and error handling out of the box

#### 🔑Key features

- **Automatic instrumentation** of MCP tool calls – each invocation gets its own span
- **Built‑in OpenTelemetry NodeSDK** – no manual SDK configuration needed
- **Zero‑code integration** – just import and go
- **OTLP export** to Dynatrace – the package reads OTEL\_EXPORTER\_OTLP\_ENDPOINT and DYNATRACE\_API\_TOKEN environment variables and sends your traces to Dynatrace for you
- **Comprehensive tracing** with error tracking – exceptions are captured and spans are marked with error status automatically

#### 🚀Getting started

Install the package from npm:

```markup
npm install <a href="/user/39872">@theharithsa</a>/opentelemetry-instrumentation-mcp

```

For most users, the **auto‑registration** approach is easiest: at the very top of your application’s entry point (e.g., src/index.ts), add a single import line:

```auto
import '@theharithsa/opentelemetry-instrumentation-mcp/register';

```

That’s it! The package will start the OpenTelemetry SDK, load the default Node instrumentations and the MCP instrumentation, and export spans to your Dynatrace tenant. Just ensure these environment variables are set

- **OTEL\_EXPORTER\_OTLP\_ENDPOINT** – your Dynatrace OTLP endpoint (e.g., https://{environmentid}.apps.dynatrace.com/api/v2/otlp/v1/traces)
- **DYNATRACE\_API\_TOKEN** – a token with trace ingest permissions

 ![theharithsa_0-1754163395288.png](https://global.discourse-cdn.com/dynatrace/original/3X/1/0/10186cbc8e5c246e20d1be7e8c16ac87e312a4b7.png)

For advanced use cases, you can create your own NodeSDK instance and pass new McpInstrumentation() alongside other instrumentations

#### 🛠 Custom attributes

Need to enrich spans with more context? Because the instrumentation runs your tool callback in the proper OpenTelemetry context, you can obtain the active span in your callback and set attributes like the model name, API name or custom metadata:

```auto
import { trace, context } from '@opentelemetry/api';

// inside your MCP tool callback…
const span = trace.getSpan(context.active());
span?.setAttribute('model.name', modelName);
span?.setAttribute('api.name', apiName);
// …rest of your logic

```

Alternatively, you can modify the instrumentation itself to set default attributes on every span.

#### 🔗Useful links

- 📦 **npm package** : [@theharithsa/opentelemetry-instrumentation-mcp](https://www.npmjs.com/package/@theharithsa/opentelemetry-instrumentation-mcp?activeTab=readme)
- 💻 **GitHub repo** : [github.com/theharithsa/opentelemetry-instrumentation-mcp](https://github.com/theharithsa/opentelemetry-instrumentation-mcp)

If you try out the package, let us know what you think! Pull requests and issues are welcome on GitHub.
