Commit Graph

144 Commits

Author SHA1 Message Date
lalex df3c719317
Add semantic conventions for Resource and Trace attributes (#502)
* Add semantic conventions for Resource and Trace attributes

* Add SCHEMA_URL pointing to the scheme used for code generation

* Fix setting of SERVICE_NAME in default Resource instance

* Add information about semantic conventions to README.md
2021-12-08 20:51:13 -05:00
Brett McBride 44575d74e6
combining otlp span converters (#494)
* span converter rework
- combine otlp's grpc and http span converters into one
- adjust UsesSpanConverterTrait to always deal with arrays of spans, since span processors only accept arrays
Still to do:
- combine duplicated grpc/http span converter tests

* tidy

* make internal otlp span converted methods private
2021-12-06 23:24:34 -05:00
Brett McBride 8649206eaa
switching span processor selection to language-specific (#497)
see https://github.com/open-telemetry/opentelemetry-specification/pull/2172#issuecomment-982312473
2021-12-01 18:55:55 -05:00
Brett McBride 2c1eb54946
Revert "Otlp centralised config (#488)" (#491)
This reverts commit 70d4dc25df.
2021-11-28 18:45:13 -05:00
Brett McBride 70d4dc25df
Otlp centralised config (#488)
* WIP

* Return Opts object so chain config

* More WIP

* combining otlp and grpc config
based on SeanHood's initial work for #383, I've fleshed out ConfigOpts, and used it to
simplify the configuration of the http and grpc exporters

* tidy

* changing compression to string, per spec

* update example - insecure defaults to false per spec

* moving more config into ConfigOpts
now both http and grpc exporters have almost the same constructor (todo Grpc accepts a SpanConverter
but http does not)

* removing unused SpanConverter param

* remove unused function

* test coverage for grpc exporter

Co-authored-by: Sean Hood <me@seanhood.co.uk>
2021-11-28 18:27:00 -05:00
Brett McBride d9e2f5238b
distributed tracing example (#483)
* distributed trace example

* screenshots

* remove xdebug settings

* style fixes

* fixing composer.json ref

* clean up collector config

* fix typo

* code review feedback

* fixing psalm platform reqs
the bug was fixed upstream, so revert our workaround

* install otel lib from github, commit lock file
2021-11-22 12:10:26 -05:00
Brett McBride c464706ff4
default tracer (#479)
* set/get default tracer

* adding a default tracer example
2021-11-21 14:11:31 -05:00
Brett McBride 6b2acca0ec
Configuration from environment variables. (#469)
* Configuration from environment variables.
Allow configuring resources, (some) exporters, samplers, and span processors from environment.
Add a TraceProviderFactory as a top-level method of creating a span processor from environment variables.
I think that other span exporters can be made to be env-configurable, but holding off until an upcoming improvement to use psr-7 discovery lands, which should simplify
most of the exporters.

* setting io.opentelemetry.contrib.php as the default tracer name

* review feedback
- Throwing InvalidArgumentExceptions from some factories.
- Removing guzzle client from ExporterFactory.

* magic values to consts

* moving queue init to property

* adding root sampler to parentbased sampler description
this makes parent-based description more meaningful, and also useful for test assertions

* fixing tracer provider factory tests

* improving span processor factory tests

* use ReflectionObject in test

* Adding a trait for retrieving and processing environment variables

* empty value must be treated as unset

* fixing default service name
2021-11-17 17:23:41 -05:00
Timo Michna d497f4e745
Add Logger SpanExporter, Logger ExporterDecorator and other logging related components. (#460)
* Add psr/log as dependency

* Add monolog as dev dependency

* Depend on AttributesInterface

* Add StatusDataInterface

* Change psr/log to PHP7.4 compatible version

* Add vfsstream to mock filesystem

* Move ConsoleSpanExporter

* Add PSR severity mapping

* Add SpanConverterInterface

* Add FriendlySpanConverter

* Add NullSpanConverter

* Add UsesSpanConverterTrait

* Add SpanExporterDecoratorTrait

* Add SpanExporterTrait

* Add LoggerAwareTrait

* Add SimplePsrFileLogger

* Use FriendlySpanConverter

* Add AbstractDecorator

* Add LoggerExporter

* Add LoggerDecorator

* Fix line breaks in log formatting

* Change accessibility of granularity setter to public

* Add trace logging examples

* Fix CS

* Add EventTest

* Add loggerName parameter

* Paint it green

* Fix CS

* Activate native PHP asserts for tests
2021-11-08 19:48:27 -05:00
Brett McBride fd33eb580a
Bugfix/batch processor (#459)
* updating BatchSpanProcessor to spec
The spec for SpanProcessor::shutdown() says 'MUST include the effects of ForceFlush', so implement that logic and add a test (also updated a couple of other tests to add a new expectation on forceFlush)
The spec for SpanProcessor::forceFlush() also says that built-in span processors MUST call forceFlush() on the exporter.
Bugfix: SpanInterface::scheduledDelayMillis clearly accepts milliseconds, but time checking arithmetic uses nanoseconds. Adding a constant to convert between the two (todo, write a test?)

* renaming const, adding batch example

* style fix

* unit tests for batch span processor delay

* improving code coverage of BatchSpanProcessor
2021-11-01 06:17:54 -04:00
Brett McBride 08916531be
docs/updated examples (#455)
* span resources example
example code for setting span resource attribute, which are sent as part of the payload of each span. also adds to ConsoleSpanExporter a
representation of each span's resources

* concurrent spans example

* linting, updating ConsoleSpanExporter tests

* adding some stable resource constants

* update span name
span-n should be more obvious when reading a trace
2021-10-30 13:57:56 -04:00
Sean Hood c972954aa4
Add docs + ConsoleSpanExporter (#442)
* Add docs + ConsoleSpanExporter

- [ ] Add tests
- [ ] Support Events/Attributes/Status
- [ ] Kind should return friendly string not int

* Update ConsoleSpanExporter to match SpanExporterInterface

* Tests! and more

* Tests!
* Kind now returns the API name rather than the integer
* Added attributes
* Added status
* Added events

* Fix trace parent id

* Update docs + examples

* Make phan/phpstan/psalm/style happy

* Make palm happy on PHP 7.4?

* Document more functions
2021-10-28 17:15:16 -05:00
George Dietrich 01c388e02c
Reorganize types (#434)
* Create and move namespaces into `src/` directory

* Update `composer.json`

Move test helpers outside of `SDK` namespace into `Tests`

* Follow PSR naming conventions for interfaces

* Follow PSR naming conventions for abstract classes and traits

* Do a pass on CI configs

* Add examples directory to cs-fixer config

* Fix some erroneously renamed type names
2021-10-03 06:32:46 -04:00
George Dietrich 6cffcbe5a0
Span Refactor (#422)
* First pass at updating Span API

* First pass at updated Span implementation

* Update SDK Span return types to `ReadWriteSpan`

Drop support for PHP 7.3

* Finish initial implementation

* Implement `SpanData`

* Implement `StatusData`

* Re-implement and rename `NoopSpan` to `NonRecordingSpan`

* Updates to support `SpanData` in exporters/span processors

* Add timestamp conversion helper methods

Update Exporters to use `SpanData`
Start updating Exporter tests
Implement non immutable `SpanData` test helper class

* Finish updating exporters/converters

* Fix next batch of tests

* First pass at `Tracer` refactor

Leverage a `SpanBuilder` to create the span
Use a dedicated object to share state

* Just use `NonRecordingSpan` constructor versus `create`

Start of adding tests for new Tracer implementation

* Remove some unneeded `max`

Make `Sampler` the 2nd arg to `TraceProvider`
Fix Integration tests

* Add `NoopSpanProcessor`

Continue updating/adding tests

* Install mockery

Ensure span processor is called with expected contexts/spans

* Update `SpanData` to directly return dropped amounts

Make `SpanProcessor#onStart` take a `ReadWriteSpan`
Update empty span fallback name

* Revamp `Clock` interface/implementation

* Add some additional doc comments

Continued work on updating test coverage

* Add more `Span` tests

* Get tests to a passing state

* Fix type errors

* Make CI happy

* Apply limits within `Span` constructor and `SpanBuilder` logic

Add test coverage for these cases
2021-09-29 19:10:07 -04:00
George Dietrich 500ff88cdb
Context propagation refactor (#410)
* Update `TextMapPropagator` interface

* Update trace context propagator

* Implement `ImplicitContextKeyed`

First pass at moving span activation outside of `Tracer`

* Set span as current when activating in `Tracer`

Fix some tests

* Make CI happy

* Use single method to get context

Add doc comments where needed
Update spec links to use specific version

* Normalize `Link` to use `getContext` as well

Reintroduce `getContext` to `ReadableSpan`
Make CI happy

* Update/Rename getter/setter type to be spec compliant

* Revert `Link` method name change

Makes it more clear you're getting a `SpanContext` not some sort of`LinkContext`

* Rename `makeCurrent` to `activate`

* Rename `Context` methods to better reflect their purpose

* Make carrier the 2nd arg

Implement `KeyedArrayAccess` and rename the propagation getter/setter to `ArrayAccessGetterSetter`

* Fix typing issues
2021-09-14 20:46:35 -04:00
Sean Hood c07dee23ff
OTLP/HTTP First Pass (#352)
* OTLP/HTTP First Pass

This PR Implements OTLP/HTTP (Protobuf)

As it stands the AlwaysOnOTLPExample works sending Traces to the Collector. The SpanConverter was pulled directly from the GRPC implementation.

OTLP/HTTP (Json) has an interesting history behind it and looks harder to support:
https://github.com/open-telemetry/opentelemetry-specification/issues/786

TODO:
- [ ] Tests
- [ ] Support all config params from the constructor (compression, timeout, headers)
- [ ] Endpoint validation

* Fixes Phan Error

* OTLP/HTTP: The wait is over

* Tests tests tests
* Add headers supports
* Supports 4 of 6 Env Vars
* Rejects otlp/json (for now)
* Might support gzip (needs testing)

* Unrelated psalm fixes

* chore: make style

* OTLP/HTTP: Copy/paste SpanConverter Tests

I feel like the OTLP/HTTP and OTLP/GRPC Classes could be more integrated since their SpanConverters are identical

* OTLP/HTTP: Request body should actually send the payload!

* Return InvalidArgumentException when invalid headers are passed rather than silently fail

* Re work process headers function so it\'s called in the constructor rather than later at export

* This fixes a number of test with the span converter, basic types work: string, int, float, bool.

* This fixes converting arrays passed into attributes; and adds tests too
2021-07-21 13:35:06 -04:00
Tobias Bachert d908922a79
Remove Tracer::endActiveSpan() (#365) 2021-06-21 10:32:59 -04:00
Onyemenam Ndubuisi 6ecb85af75
Add working example and tests for improvements (#331)
* Adjust exporters and exporter tests as necesasary

* Make style fixes

* Fix static analysis errors

* Add PHPStan fix

* Fix Psalm error
2021-05-27 14:29:12 -04:00
Amber Sistla e5272c532e
Update automated collector example to be cache independent and add children spans to example. (#305)
* * Made independent of docker cache... :)
    * Ignore docker-compose orphans.
    * Made `make collector` section in Makefile since the collector related tests now have their own docker-compose and needed a d-c up as well.
    * updated the example file to account for an error in the shouldSample function call, changed `RECORD_AND_SAMPLED` to `RECORD_AND_SAMPLE`, and added a children to a parent root span.

* Typo.

* Two different ways to make children spans.

* Style.

* Added database/internal/external spans.

* Address `psalm` error.

* Formatting.
2021-05-10 14:57:17 -04:00
Sean Hood 8a135019cc
OTLP/GRPC Exporter Implementation (#272)
* Adding Proto to opentelemetry-php
Signed-off-by:Ritick Gautam <riticksinghrajput@gmail.com>

* Updated the script for generating proto folder in root

* Moved shell file in script folder
updated .gitignore

* Removed opentelemetry-proto

* Bug fixed

* added docker-compose.proto.yaml
updated script file
updated Makefile

* Update docker-compose.proto.yaml

* Updated README.md

* OtlpGrpc

* Added Request-response

* Example Updated

* Updated Span Converter

* small fixes

* modified: SpanConvertor.php

* (WIP): Partially working OTLP/GRPC Exporter

What's working?
* Sends spans to the Otel Collector
* Spans contain: Attributes, Status Code, Kind, Start/End timestamp, Lib Version
* Sucessfully sent OTLP to Honeycomb.io

What's not working?
* Need to rebase main onto this branch
* Trace ID and Span ID are too long, and have been fudged to trim them.
* No tests. Unit/Integ
* Events on spans haven't been tested
* Child spans haven't been tested
* Example code needs to be updated (been testing with laravel-otel)
* Need to check the status returned
* Links not implemented
* Generally just unfinished

Anything more to add?
* Thank you to the Ruby OTLP Exporter, lots of inspiration was taken from there

* Fixed traceid and spanid hacks; Now supports Events

* Use localhost:4317 for the default host; + cleanup

* Split code between Exporter.php and SpanConverter.php; Beginnings of tests

* More progress on tests, array's now correctly get converted. Also ran `make style` to format the code

* * Ironed out passing in headers. Could not figure out how best to validate the format php grpc wants the metadata to be in so accepting just the required string format now.
* Beginnings of tests for the Exporter
* Compression now configurable, not tested
* Removed ServiceName from being passed to the Exporter, I believe this should be set as an Attribute on a Resource in the TracerProvider
* Checking the status code coming back from GRPC client, Otel Spec says transient errors MUST be retried, retries not yet implemented: ffc85ddfd9/specification/protocol/exporter.md (retry)

* Add (failing) test for converting SDK Span to OTLP Span

* I'm struggling to set (or even get) an end timestamp for the span.
* Attributes not implemented on Events

* Further progress on Tests for the Exporter

* SpanConverter now translates attrs on Events

* Add opentelemtry-proto files

* Ran `make style' on proto. Do we want this?

I pushed the proto files and build is complaining, not sure if we want to exclude this dir from linting or not?

Testing it formatted so I can try to get this build green.

* Few changes in this one..

1. Moved out ResourcesSpans into the SpanConverter
2. Time is almost fixed, well tests pass but... I learned the clock didn't work as I expected it to. Wall clock and monotonic clock are entirely unrelated. I still think this needs more work but I _think_ it tests that the duration is correctly set on the otlp span.
3. ResourceInfo is now populated on otlp ResourceSpans.

* Fix some of the complaints from static analysis

* Revert "Ran `make style' on proto. Do we want this?"

No, we do not want generated code to be formatted with php-cs-fixer

This reverts commit 996b473ad3.

* make style

* Static analysis fixes

* Hopefully this adds the grpc extension

* Hopefully this adds the grpc extension

* Some Psalm fixes

* Added a few comments; disable testing of InstrumentationLibrary until it's implemented

Co-authored-by: Ritick Gautam <riticksinghrajput@gmail.com>
Co-authored-by: Ritick Gautam <41835832+riticksingh@users.noreply.github.com>
2021-05-05 14:17:24 -04:00
lalex edcb4327ed
Update sampling behavior (#289)
* Update sampling behavior

* Change shouldSample() method signature to accept the Context
* Default sampler is ParentBased(root=AlwaysOn)
* Avoid to start sampled and non-recording span, return NooSpan
* Change names of SamplingResult constants: DROP, RECORD_ONLY, RECORD_AND_SAMPLE
* Return an updated TraceState in SamplingResult (parent TraceState by default)
* Merge Attributes from the SamplingResult with the Attributes provided in the startSpan method

* Add an integration test case for an overridden TraceState by the Sampler
2021-03-22 22:46:27 -04:00
Amber Sistla 76304a2b7b
Experimental exporter, span converter, example, and tests. (#276)
* Experimental New Relic exporter, span converter, example, and tests.

* Test case mod.

* Fixed comment.

* Addressed PR issues.
* Created consts for `DATA_FORMAT` and `DATA_FORMAT_VERSION_DEFAULT`
* Commented out echos pending logging implementation.
* Removed middleware handler causing mem leak.
2021-03-17 11:20:02 -04:00
lalex 644d13bf17
Add ContextValueTrait and Scope to store in Context (#264)
* [WIP] Add ContextValueTrait and Scope to store in Context

* Add tests for ContextValueTrait

Add test for the Context interaction during the Span creation

Generate the new Trace ID for every root span

* Fix phan warnings

* Add Context\Scope test
2021-03-12 10:46:46 -05:00
Amber Sistla bb0bbafec1
Basic example to send zipkin style data to a New Relic backend. (#275) 2021-03-10 11:07:24 -05:00
Onyemenam Ndubuisi 3c18f3a4ab
Feature/add record exception (#255)
* Add recordException event, test and examples

Fix phpstan errors

* Attempt to fix test failures
2021-02-26 11:20:02 -05:00
Ritick Gautam 094333d422
Added OTLP/HTTP JSON Exporter (#210)
* Added OTLP/HTTP JSON Exporter

Signed-off-by:Ritick Gautam<riticksinghrajput@gmail.com>

* Updated SpanConverter

* Fix vendor/bin/psalm

* Updated TestCase

* Updated OtlpExportertest accordingly #208
Updated TestCase

* Updated OTLPSpanConverterTest

* Updated OTLPExportertest

* BugFixed

* bug fixed

* Updated: otlpExporter
Updated: testcase

* Updated namespace with StuldyCase

* Renamed the namespace

* Updated php-cs-fixer
2020-11-09 23:04:19 -05:00
Dalibor Karlović 16c3f97743
chore: add static analysis for tests, examples (#208) 2020-11-04 23:00:11 -05:00
Beniamin 618a983c83
remove global span (#171)
* remove global span creation when Tracer is initialized and fix batch exporter not exporting in batches but one by one

* use the monotonic clock instead of realtime clock to compute time elapsed - realtime clocks  can move backwards

* add the NoopSpan. It will be used as the root Span

* Use NoopSpan for new traces

* Generate a new context if the root span is noop

* Remove comments

* Inline variable

* Must set parent as active span so that span ID is propagated

* Revert "Must set parent as active span so that span ID is propagated" as context can't be used as span

This reverts commit 985fa5e2c4a1b4b99f9ea15f4589da055652b091.

* Load NoopSpan when required

* Fixed regression: creating a Tracer with an existing context is now supported again.

* Add variable to improve readability

* Rename variable for clarity.

* fix failing psalm checks and add test for root NoopSpan

Co-authored-by: Ben Magee <ben@bmagee.com>
2020-10-27 15:27:05 -04:00
Dalibor Karlović 72ff1f2b6c
Issues found by Psalm / PHPStan level 4 and CS Fixer (#185)
* fix: small issues found by Psalm level 4

* fix: small issues found by PHPStan level 4
2020-10-04 12:11:37 -04:00
André Luis Gomes dd1d1d704d
Fix AlwaysOffTraceExample.php Sample (#195)
The `$span->addEvent()` waits a $timestamp as second argument, but
we are sending `new Attributes([...` as aprameter.
2020-10-04 12:10:17 -04:00
Onyemenam Ndubuisi df87435383
rename zipkin and jaegar example tracing as appropriate (#190)
* rename zipkin and jaegar example tracing  as appropriate
make file updates to reflect changes

fixes #189

* make minor grammar fix
2020-09-28 10:54:52 -04:00
Artem Prozorov b49df469d6
Metrics api (#155)
* Metrics API Templating

* Metrics API Templating

* Adding Style

* Added base Metrics Providers

* Rework this commit

* Minor changes in exporter

* Added test for abstract metrics exporter

* Fixed namespace in test

* Added Metrics interface stub

* Added additional check in GlobalMeterProvicerTest

* Style fixes

* Added fixes according to php stan

* Removed comments

* Refactored Exporter

* Removed unused array from AbstractExporter

* Refactored API and aded base files

* Installed new dependencies

* Added example for Prometheus Metrics

* Fixed Phan config

* Added UpDownCounter and tests for it

* Fixed prometheus misspelling, renamed shortcut command for metrics example

* Added docblocks

* Refactored structure of metrics prometheus example

* Added info in readme how to run metrics prometheus example

* Style fixes for counters

* Removed unused import in test

* Added more typization for metric labels

* Added todo for later

* Added versioning in MeterProvider

* Fix for versioning in MeterProvider

* Added ValueRecorder class

* Fixed typo in docblock

* Removed Assert library

* Removed assert library from phpstan config

* Fixed style

* Removed ValueRecorder from this branch

Co-authored-by: Bob Strecansky <bob.strecansky@gmail.com>
2020-08-10 16:32:19 -04:00
Beniamin c2476dfda9
split Trace SDK in sub-namespaces and create new area for contrib (#97)
move all tests in the same root directory - will be easy to follow

remove errant test and whitelist the library code for coverage instead of tests

inherit JaegerExporter from Zipkin since we are using the zipkin protocol to export to Jaeger
2020-06-17 11:24:08 -04:00
Bob Strecansky d18fa6eeff
Change to timestamps and weave the hrtime web (#83)
* Change to timestamps and weave the hrtime web

* Fixed comma

* Updating Test

* Updating Tests

* WIP

* WIP

* Change to timestamps and weave the hrtime web

Test revamp (#90)

* Moving Tests

* Moving Tests

Adding more information to README.md (#84)

Fix relative link to AlwaysSampleTraceExample.php (#91)

Updating Tests

* WIP

* Working Time example with all requested updates
2020-05-22 20:10:27 -04:00
Bob Strecansky 55cc8b6ff1 Update Examples with SpanKind (#82)
* Update Examples with SpanKind

* make style
2020-05-15 16:27:38 -04:00
Beniamin e5eda43ad9
Jaeger exporter (#70)
* make zipkin-exporter implementation simpler

* add Jaeger exporter and fix zipkin exporter timestamps

* move zipkin converter logic outside of exporters

* start containers before running examples

* fix open-telemetry badge codecov.io url

* fix phpunit whitelist after api and sdk splitting
2020-04-05 16:05:52 -04:00
lalex 783ccdde06
Built-in samplers implementation (#66)
* Built-in samplers implementation
- AlwaysOffSampler
- AlwaysOnSampler
- AlwaysParentSampler
- ProbabilitySampler

* Fix code standards

* Apply an API interface refactoring

* Fix sampler examples

* Fix coding standards

* Move files around, fix small issues

* Fix doc block and coding standards

Co-authored-by: Levi Morrison <levi.morrison@datadoghq.com>
2020-04-01 17:53:43 -04:00
Levi Morrison 3262c429ff
Add API Interfaces (#64)
* Migrate src/ to sdk/ and api/

Co-authored-by: Bob Strecansky <bob.strecansky@gmail.com>

* Rename TracerFactory to TracerProvider

This follows opentelemetry/oteps#76.

Also start moving sdk tests into the sdk/Tests folder

* Touch up SpanStatus and ending spans

* Remove getTracerVersion and getTracerName

These aren't described in the spec -- we can add them back later
if we need to, but I suspect they belong only in the SDK, if anywhere.

* Update phan config and fix some warnings

* Start writing SpanOptions

Also start fixing examples, currently broken

* Fix PhpUnit 9 incompatibilities

Co-authored-by: Bob Strecansky <bob.strecansky@gmail.com>
2020-03-26 19:31:19 -04:00
Bob Strecansky a3a5cab776
Updating README.md (#61) 2020-03-11 22:57:02 -04:00
Alan Storm d8a554b598
Fixes Broken Example Code and Link in README (#59)
* Give examples working code

* Fix link in README

* php-cs changes
2020-02-12 21:40:44 -05:00
Nenad Stojanovikj 7fe89db0ae Add php-cs-fixer (#50)
* Add php-cs-fixer to dev requirements

* Ignore php-cs-fixer cache file

* Add style guide configuration file

* Correct style of all PHP files

* Add Makefile target for style fixing
2020-01-24 08:15:22 -05:00
Beniamin 3d56cb7adf implement ZipkinExporter::export, and Process spans in Tracer (#41) 2020-01-20 21:48:15 -05:00
Beniamin 0991f72146 TracerFactory implementation (#38)
* implement TracerFactory, begin migration to recommended library layout, use docker-compose and make to simplify development

* add tests for all TracerFactory method, move TraceFactory configuration in constructor

* run phan in travis-ci build

* rename namespace Tracing into Trace
2020-01-07 08:39:14 -05:00
Bob Strecansky c863d37cff
Performing Always and Never Sample Steps (#30)
* Performing Always and Never Sample Steps

* Updating examples to remove builder

* Updating examples to remove builder

* Removing builder from always off trace example
2019-12-10 13:48:22 -05:00