Skip to content

Commit

Permalink
fix: changes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
GCalmels committed Jul 30, 2024
1 parent b1bc554 commit ffce4f6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
5 changes: 2 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
- Trace context propagation from incoming **requests** to **consumers**, **outgoing http calls** and **databases** (using [`sqlcommenter`](https://google.github.io/sqlcommenter/))
- Configurable blacklisting of requests by path to avoid useless traces, eg. `/metrics` or `/_healthz`
- Automatic log inclusion with configurable log level and channels
- Disabling tracing with the `NoopTracerProvider` thanks to OTEL_SDK_DISABLED=true

#### Metrics

Expand Down Expand Up @@ -39,15 +38,15 @@ composer require worldia/instrumentation-bundle <your-exporter>

You will aso need to install an [exporter implementation](https://packagist.org/packages/open-telemetry/exporter-otlp?query=open-telemetry%2Fexporter-) and `APCu` is required by the prometheus exporter.

````
```
Add to ```bundles.php```:
```php
return [
// Other bundles
Instrumentation\InstrumentationBundle::class => ['all' => true],
];
````
```

**Minimal configuration**
See the complete [configuration reference here](./docs/config-reference.md) or run `bin/console config:dump-reference instrumentation`.
Expand Down
7 changes: 7 additions & 0 deletions src/DependencyInjection/config/tracing/tracing.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Instrumentation\Tracing\Propagation\RegexIncomingTraceHeaderResolver;
use Instrumentation\Tracing\Sampling\TogglableSampler;
use Instrumentation\Tracing\Serializer\Normalizer\ErrorNormalizer;
use Instrumentation\Tracing\TogglableTracerProvider;
use Instrumentation\Tracing\TraceUrlGeneratorInterface;
use Instrumentation\Tracing\Twig\Extension\TracingExtension;
use OpenTelemetry\API\Trace\TracerProviderInterface;
Expand Down Expand Up @@ -90,6 +91,12 @@
])
->public()

->set(TogglableTracerProvider::class)
->decorate(TracerProviderInterface::class)
->args([
service('.inner'),
])

->set(MainSpanContextInterface::class, MainSpanContext::class)

->set(TracingHandler::class)
Expand Down
34 changes: 34 additions & 0 deletions src/Tracing/TogglableTracerProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

/*
* This file is part of the worldia/instrumentation-bundle package.
* (c) Worldia <[email protected]>
*/

namespace Instrumentation\Tracing;

use OpenTelemetry\API\Trace\NoopTracer;
use OpenTelemetry\API\Trace\TracerInterface;
use OpenTelemetry\API\Trace\TracerProviderInterface;
use OpenTelemetry\SDK\Sdk;

class TogglableTracerProvider implements TracerProviderInterface
{
public function __construct(private TracerProviderInterface $decorated)
{
}

/**
* @param array<non-empty-string,mixed> $attributes
*/
public function getTracer(string $name, string|null $version = null, string|null $schemaUrl = null, iterable $attributes = []): TracerInterface
{
if (Sdk::isDisabled()) {
return new NoopTracer();
}

return $this->decorated->getTracer($name, $version, $schemaUrl, $attributes);
}
}

0 comments on commit ffce4f6

Please sign in to comment.