open-telemetry / open-telemetry/opentelemetry-php

Monolog Bridge (open-telemetry/opentelemetry-logger-monolog) does not define all its dependencies

Open
#1,943 5 comments 0 reactions 1 assignee View on GitHub

@aleksandrpanshin-vaimo is already working on this.

Since Jun 10, 2026.

bug
Dominant language
PHP
Stars
912
Forks
232
Avg merge
7d 16h
Merged PRs (30d)
4

Description

Describe your environment

I'm on MacOS, and my PHP version is 8.1, although this is irrelevant, since I have the same issue on my Jenkins that is running Linux in k8s

% php --version
PHP 8.1.33 (cli) (built: Jul  1 2025 21:17:52) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.33, Copyright (c) Zend Technologies
    with Xdebug v3.4.3, Copyright (c) 2002-2025, by Derick Rethans
    with Zend OPcache v8.1.33, Copyright (c), by Zend Technologies

I have initiated a tiny test application with the following composer.json:

{
    "name": "aleksandrpanshin/otel-monolog",
    "require": {
        "open-telemetry/opentelemetry-logger-monolog": "^1.2"
    },
    "authors": [
        {
            "name": "Aleksandr Panshin",
            "email": "aleksandr.panshin@vaimo.com"
        }
    ]
}

I intentionally do not declare any other dependencies to make sure that the issue persists even in the smallest possible env.

Steps to reproduce

Then I proceed with the following php script in the project:

<?php

declare(strict_types=1);

use Monolog\Level;
use OpenTelemetry\API\Globals;
use OpenTelemetry\Contrib\Logs\Monolog\Handler;

require_once __DIR__ . '/vendor/autoload.php';

$loggerProvider = Globals::loggerProvider();
$handler = new Handler($loggerProvider, Level::Debug);

$monolog = new Monolog\Logger('test', [$handler]);

$monolog->info('test', [
    'exception' => new \Exception('Test exception'),
]);

What is the expected behavior?

Since in this case Globals::loggerProvider() would return \OpenTelemetry\API\Logs\NoopLoggerProvider, which in turn will create \OpenTelemetry\API\Logs\NoopLogger instance, I expect this code to pretty much do nothing and return 0 status code.

What is the actual behavior?

% php test.php 
PHP Fatal error:  Uncaught Error: Class "OpenTelemetry\SemConv\Attributes\ExceptionAttributes" not found in vendor/open-telemetry/opentelemetry-logger-monolog/src/Handler.php:80
Stack trace:
#0 vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(44): OpenTelemetry\Contrib\Logs\Monolog\Handler->write(Object(Monolog\LogRecord))
#1 vendor/monolog/monolog/src/Monolog/Logger.php(391): Monolog\Handler\AbstractProcessingHandler->handle(Object(Monolog\LogRecord))
#2 /vendor/monolog/monolog/src/Monolog/Logger.php(607): Monolog\Logger->addRecord(Object(Monolog\Level), 'test', Array)
#3 test.php(22): Monolog\Logger->info('test', Array)
#4 {main}
  thrown in vendor/open-telemetry/opentelemetry-logger-monolog/src/Handler.php on line 80

Additional context

What happens here is Handler actually depends on open-telemetry/sdk and open-telemetry/sem-conv for exceptions processing, but never declares those dependencies (outside of --dev).

The easiest fix I can imagine is actually requiring these packages in open-telemetry/opentelemetry-logger-monolog.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.