basis-company/opentelemetry

This package is abandoned and no longer maintained. The author suggests using the basis-company/telemetry package instead.

0.0.6 2020-12-14 09:28 UTC

This package is auto-updated.

Last update: 2021-08-17 19:08:26 UTC


README

Use basis-company/telemetry instead!

OpenTelemetry php library

No Maintenance Intended License Build Status Scrutinizer Code Quality Code Coverage Latest Version Total Downloads

Installation

The recommended way to install the library is through Composer:

$ composer require basis-company/opentelemetry

Tracing

Library is under active development, but simple example should be present in readme.
In addition, see tracing tests for full-featured example.

<?php

use OpenTelemetry\Tracing\Builder;
use OpenTelemetry\Tracing\SpanContext;

$spanContext = SpanContext::generate(); // or extract from headers

$tracer = Builder::create()->setSpanContext($spanContext)->getTracer();

// start a span, register some events
$span = $tracer->createSpan('session.generate');

// set attributes as array
$span->setAttributes([ 'remote_ip' => '5.23.99.245' ]);
// set attribute one by one
$span->setAttribute('country', 'Russia');

$span->addEvent('found_login', [
  'id' => 67235,
  'username' => 'nekufa',
]);
$span->addEvent('generated_session', [
  'id' => md5(microtime(true))
]);

$span->end(); // pass status as an optional argument

Testing

To make sure the tests in this repo work as you expect, you can use the included docker test wrapper:

1.) Make sure that you have docker installed
2.) Execute ./resources/test-using-docker from your bash compatible shell.