Giter Site home page Giter Site logo

overtrue / laravel-open-telemetry Goto Github PK

View Code? Open in Web Editor NEW
11.0 1.0 0.0 131 KB

This package provides a simple way to add OpenTelemetry to your Laravel application.

License: MIT License

PHP 100.00%
laravel-package opentelemetry opentelemetry-php opentracing tracing-library opentelemetry-laravel

laravel-open-telemetry's Introduction

Laravel OpenTelemetry

This package provides a simple way to add OpenTelemetry to your Laravel application.

CI Latest Stable Version Latest Unstable Version Total Downloads License

Installation

You can install the package via composer:

composer require overtrue/laravel-open-telemetry

Usage

Configuration

Publish the configuration file:

php artisan vendor:publish --provider="Overtrue\LaravelOpenTelemetry\OpenTelemetryServiceProvider" --tag="config"

Update the environment variables

OTLE_ENABLED=true

OTLE_SERVICE_NAME=your-service-name

OTLE_AUTO_TRACE_REQUESTS=true

OTLE_DEFAULT_TRACER=http-json

OTLE_HTTP_JSON_ENDPOINT=http://localhost:4318/v1/trace

OTLE_HTTP_BINARY_ENDPOINT=http://localhost:4318/v1/trace

OTLE_GRPC_ENDPOINT=http://localhost:4317/v1/trace
//... 

and other environment variables, you can find them in the configuration file: config/otle.php.

Register the middleware

you can register the middleware in the app/Http/Kernel.php:

protected $middleware = [
    \Overtrue\LaravelOpenTelemetry\Middlewares\MeasureRequest::class,
    // ...
];

or you can set the env variable OTLE_AUTO_TRACE_REQUESTS to true to enable it automatically.

Watchers

This package provides some watchers to help you trace your application:

  • Overtrue\LaravelOpenTelemetry\Watchers\DatabaseQueryWatcher to trace database queries.
  • Overtrue\LaravelOpenTelemetry\Watchers\CacheWatcher to trace cache operations.
  • Overtrue\LaravelOpenTelemetry\Watchers\QueueWatcher to trace job execution.
  • Overtrue\LaravelOpenTelemetry\Watchers\RedisWatcher to trace redis operations.
  • Overtrue\LaravelOpenTelemetry\Watchers\HttpClientWatcher to trace http client requests.
  • Overtrue\LaravelOpenTelemetry\Watchers\LogWatcher to trace log operations.

You can enable or disable them in the configuration file: config/otle.php.

Custom span

You can create a custom span by using the Overtrue\LaravelOpenTelemetry\Facades\Measure facade:

use Overtrue\LaravelOpenTelemetry\Facades\Measure;

Measure::span('your-span-name')->measure(function() {
    // ...
});

or manually start and end a span:

Measure::start('your-span-name');

// ...

Measure::end();

and you can modify the span attributes by using a closure:

Measure::start('your-span-name', function($span) {
    $span->setAttribute('key', 'value');
    // ...
});

// ...
Measure::end();

of course, you can get the span instance by using the Measure::span() method:

$span = Measure::span('your-span-name');
$span->setAttribute('key', 'value');
$scope = $span->activate();

// ...

$span->end();
$scope->detach();

Contributing

You can contribute in one of three ways:

  1. File bug reports using the issue tracker.
  2. Answer questions or fix bugs on the issue tracker.
  3. Contribute new features or update the wiki.

The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.

❤️ Sponsor me

如果你喜欢我的项目并想支持它,点击这里 ❤️

Project supported by JetBrains

Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.

License

MIT

laravel-open-telemetry's People

Contributors

overtrue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.