Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Open Telemetry Laravel Package

spatie/laravel-open-telemetry

Add OpenTelemetry tracing to Laravel to measure performance and follow requests across dispatched jobs and services. Export traces to tools like Jaeger or Aspecto for end-to-end visibility and debugging. (Package still in development.)

View on GitHub
Deep Wiki
Context7

title: Using samplers weight: 5

By default, the package will start traces in every request handled by your Laravel app. In production, you'll likely don't want this as it might hurt performance a little.

Instead of measuring every request, you can measure only a small portion of requests using a sampler. A sampler is a class that determines which requests should be measured. By default, the package uses the Spatie\OpenTelemetry\Support\Samplers\AlwaysSampler sampler. This can be configured using the sampler key of the open-telemetry.php config file.

If you don't want to measure every request, you can use the Spatie\OpenTelemetry\Support\Samplers\LotterySampler that ships with the package. This sampler will measure performance for roughly every 2 out of 100 requests. To use this sampler, simply specify its class name the sampler key of the open-telemetry.php config file.

Creating your own sampler

A sampler is any class that extends Spatie\OpenTelemetry\Support\Samplers. This abstract class requires you to implement a method shouldSample that should return a boolean. Here's an example where we create a CustomLotterySampler that will measure performance for roughly every 5 out of 1000 requests.

namespace App\Support\Samplers;

use Illuminate\Support\Lottery;

class LotterySampler extends Sampler
{
    public function shouldSample(): bool
    {
        return Lottery::odds(5, 1000)->choose();
    }
}

After creating your sampler, don't forget to put it's class name in the sampler key of the open-telemetry.php config file.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport