InstrumentationTrait
This trait in conjunction with the InstrumentationInterface is meant as a base for instrumentations for the OpenTelemetry API.
Instrumentations need to implement the abstract methods of this trait (besides any instrumentation specific code)
A very simplified instrumentation could look like this:
class Instrumentation implements InstrumentationInterface { use InstrumentationTrait;
public function getName(): string { return 'foo-instrumentation'; }
public function getVersion(): ?string { return '0.0.1'; }
public function getSchemaUrl(): ?string { return null; }
public function init(): bool { // This is just an example. In a real-world scenario one should only create spans in reaction of things // happening in the instrumented code, not just for the sake of it. $span = $this->getTracer()->spanBuilder($this->getName())->startSpan(); // do stuff $span->end(); } }
An user of the instrumentation and API/SDK would the call:
$instrumentation = new Instrumentation; $instrumentation->activate()
to activate and use the instrumentation with the API/SDK.
Table of Contents
Properties
- $logger : LoggerInterface
- $meter : MeterInterface
- $propagator : TextMapPropagatorInterface
- $tracer : TracerInterface
- $tracerProvider : TracerProviderInterface
Methods
- __construct() : mixed
- activate() : bool
- This method registers and activates the instrumentation with the OpenTelemetry API/SDK and thus the instrumentation will be used to generate telemetry data.
- getLogger() : LoggerInterface
- getMeter() : MeterInterface
- getName() : string
- The name of the instrumenting/instrumented library/package/project.
- getPropagator() : TextMapPropagatorInterface
- getSchemaUrl() : string|null
- The version of the instrumenting/instrumented library/package/project.
- getTracer() : TracerInterface
- getTracerProvider() : TracerProviderInterface
- getVersion() : string|null
- The version of the instrumenting/instrumented library/package/project.
- init() : bool
- This method will be called from the API when the instrumentation has been activated (via activate()).
- setLogger() : void
- setMeterProvider() : void
- setPropagator() : void
- setTracerProvider() : void
- initDefaults() : void
- validateImplementation() : void
Properties
$logger
private
LoggerInterface
$logger
$meter
private
MeterInterface
$meter
$propagator
private
TextMapPropagatorInterface
$propagator
$tracer
private
TracerInterface
$tracer
$tracerProvider
private
TracerProviderInterface
$tracerProvider
Methods
__construct()
public
__construct() : mixed
activate()
This method registers and activates the instrumentation with the OpenTelemetry API/SDK and thus the instrumentation will be used to generate telemetry data.
public
activate() : bool
Return values
boolgetLogger()
public
getLogger() : LoggerInterface
Return values
LoggerInterfacegetMeter()
public
getMeter() : MeterInterface
Return values
MeterInterfacegetName()
The name of the instrumenting/instrumented library/package/project.
public
abstract getName() : string
Tags
Return values
stringgetPropagator()
public
getPropagator() : TextMapPropagatorInterface
Return values
TextMapPropagatorInterfacegetSchemaUrl()
The version of the instrumenting/instrumented library/package/project.
public
abstract getSchemaUrl() : string|null
If unknown simply return NULL.
Tags
Return values
string|nullgetTracer()
public
getTracer() : TracerInterface
Return values
TracerInterfacegetTracerProvider()
public
getTracerProvider() : TracerProviderInterface
Return values
TracerProviderInterfacegetVersion()
The version of the instrumenting/instrumented library/package/project.
public
abstract getVersion() : string|null
If unknown or a lookup is too expensive simply return NULL.
Tags
Return values
string|nullinit()
This method will be called from the API when the instrumentation has been activated (via activate()).
public
abstract init() : bool
Here you can put any bootstrapping code needed by the instrumentation. If not needed simply implement a method which returns TRUE.
Return values
boolsetLogger()
public
setLogger(LoggerInterface $logger) : void
Parameters
- $logger : LoggerInterface
setMeterProvider()
public
setMeterProvider(MeterProviderInterface $meterProvider) : void
Parameters
- $meterProvider : MeterProviderInterface
setPropagator()
public
setPropagator(TextMapPropagatorInterface $propagator) : void
Parameters
- $propagator : TextMapPropagatorInterface
setTracerProvider()
public
setTracerProvider(TracerProviderInterface $tracerProvider) : void
Parameters
- $tracerProvider : TracerProviderInterface
initDefaults()
private
initDefaults() : void
validateImplementation()
private
validateImplementation() : void