Skip to content

MySQL2 Instrumentation Does Not Support mysql2/promise API #2918

@kaykhan

Description

@kaykhan

What version of OpenTelemetry are you using?

  • @opentelemetry/auto-instrumentations-node: v0.60.1
  • @opentelemetry/instrumentation-mysql2: v0.48.0 (pulled in by the auto-instrumentations bundle)

What version of Node are you using?

  • Node.js v20

What did you do?

I have a Node.js/Express app using the mysql2/promise API. I installed the auto-instrumentations bundle (which includes the MySQL2 instrumentation). In my code I run:

import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http/build/src/platform/node/OTLPTraceExporter";
import { NodeSDK } from "@opentelemetry/sdk-node";
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
import { resourceFromAttributes } from "@opentelemetry/resources";

export function OpenTelemetryService() {
    const env = process.env.NODE_ENV || "development";
    const traceExporter = new OTLPTraceExporter({
        url: "<redacted>/v1/traces",
    });
    const opentelemetry = new NodeSDK({
        resource: resourceFromAttributes({
            [ATTR_SERVICE_NAME]: `"<redacted>-${env}`,
        }),
        traceExporter,
        instrumentations: [getNodeAutoInstrumentations()],
    });
    return opentelemetry;
}
const [rows] = await connection.promise().query('SELECT * FROM users');

What did you expect to see?

  • A span named mysql2.query or reflecting the actual SQL statement
  • Semantic attributes including:
    • db.system = "mysql"
    • db.statement = "SELECT * FROM users"
    • db.name, db.user, etc.

What did you see instead?

  • No MySQL-specific span, or only a generic “client” span without db.system
  • In Grafana Tempo the span is misclassified (no MySQL icon) and lacks the expected semantic attributes

Additional context

  • mysql2 version: 3.14.1

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpkg:instrumentation-mysql2priority:p2Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrect

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions