Commit Graph

141 Commits

Author SHA1 Message Date
Evan 7981956060
feat(carreirs): implement environment context getter setter (#1668)
* feat(carreirs): implement environment context getter setter

Closes #1566

* tests(carrier): add EnvironmentGetterSetter missing test

* fix(carrier): modify keys empty env condition

* test: use OpenTelemetry\Tests\TestState trait to handle environment

* docs: add trace context and baggage environment carrier example

* refactor: clean up baggage and trace context examples by removing unused span logic

* test: fix Psalm static analysis failures
2025-08-04 13:25:06 +10:00
Brett McBride 2d9097492c
fixing CI complaints (#1666)
* fixing psalm complaints
use rector (and psalm) to add Override attributes, and add symfony polyfill to
provide Override in earlier php versions

* fixing more psalm complaints

* more fixes

* adding stubs for deptrac
there are some things in our code that deptrac doesn't understand or are missing
for some php versions. stub them to quieten all those violation warnings

* why not cache invalid :(

* display tools versions

* fix tools cache key

* changing cache key

* dont complain about unused psalm suppressions

* suppress invalid attribute

* quieten phpstan php8.5 complaints

* revert previous commit...now other php versions complain about an unused ignore :(

* revert typecasting in metrics aggregators

* Update src/Contrib/Otlp/ProtobufSerializer.php

Co-authored-by: Chris Lightfoot-Wild <github-clw@wild.me.uk>

* remove override stub and use the polyfill from deptrac

---------

Co-authored-by: Chris Lightfoot-Wild <github-clw@wild.me.uk>
2025-07-22 11:02:18 +10:00
Tobias Bachert 5451d57dbf
Allows API packages to specify file-based and env-based config (#1621)
* Move `ComponentProvider` and related classes to API

* Use API `ComponentProvider`

* Use API `ComponentProvider` in tests

* Add `EnvComponentLoader` API

* Add `EnvComponentLoader` example

* Ignore deptrac violations

* Remove namespace from `ComponentProvider` BC layer

* Add API requirement to config package

* Fix/suppress unrelated phpstan errors caused by `google/protobuf` `^4.31`
2025-06-16 10:24:51 +10:00
dependabot[bot] d084288a12
Update monolog/monolog requirement from ^2.3 to ^2.3 || ^3.0 (#1551)
* Update monolog/monolog requirement from ^2.3 to ^2.3 || ^3.0

Updates the requirements on [monolog/monolog](https://github.com/Seldaek/monolog) to permit the latest version.
- [Release notes](https://github.com/Seldaek/monolog/releases)
- [Changelog](https://github.com/Seldaek/monolog/blob/main/CHANGELOG.md)
- [Commits](https://github.com/Seldaek/monolog/compare/2.3.0...3.9.0)

---
updated-dependencies:
- dependency-name: monolog/monolog
  dependency-version: 3.9.0
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>

* update monolog example

* style

* drop monolog 2.3 from example

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Brett McBride <brett@deakin.edu.au>
2025-04-08 11:19:29 +10:00
Brett McBride 83cddd9157
declarative config 0.3+ support (#1452)
This brings declarative config support up to 0.3 plus some of the unreleased 0.4 features:

* porting code from Nevay/otel-sdk-configuration
* support 0.4 metric reader config
* allow empty keys
since https://github.com/open-telemetry/opentelemetry-specification/pull/4269 empty keys are allows, and NULL is no longer equivalent to unset
* update config example to remove empty objects
* remove moved component providers from composer.json
* add ComponentProviderRegistry::componentMap for instrumentation configuration
2025-01-10 10:17:14 +11:00
Brett McBride 32e301ea6a
adding otlp/file exporter (#1465)
the spec has added in-development otlp file/stdout exporter. We already supported this programmatically, so
add some factories and sdk config to allow configuration from environment (only for stdout, per spec)
2025-01-09 10:50:03 +11:00
Brett McBride 7aa3e02eb0
remove blank lines after class opening (#1468)
add the php-cs-fixer no_blank_lines_after_class_opening rule and apply to codebase
2025-01-07 21:18:52 +11:00
Brett McBride f1c982734b
add sdk-config 0.3 support for key/value headers and attributes (#1428)
- headers and attributes are now arrays with `key` and `value` elements
- headers can optionally contain a `headers_list` element which supports a lower-priority CSV of key/value entries
- attributes can optionally contain an `attributes_list` element which supports a lower-priority CSV of key/value/data-type entries
2024-11-26 11:48:31 +11:00
Brett McBride d2b15077df
use weaver to generate semconv (#1398)
update semconv generation to use the new tooling. This is fairly close to a 1:1 of what we have now,
although I noted a couple of TODOs which we might consider in future to align with what Java is
doing: split attribute up into file-per-type, and split stable/unstable.
2024-10-17 20:57:37 +11:00
Tobias Bachert 2c1da9aaec
Add `TextMapPropagator` to instrumentation context (#1401) 2024-10-16 09:42:37 +11:00
Jamie Danielson 8ed62b1e43
fix: Update collector tag in example to latest (#1384)
Follow-up from #1383. Debug exporter isn't available until v0.86.0, so this new configuration throws an error when trying to run the collector. `Error: cannot unmarshal the configuration: unknown exporters type "debug" for "debug"` Instead of setting to v0.86.0, I noticed the other docker files omitted the tag (so latest is pulled). I just updated this to match.
2024-09-24 08:35:18 +10:00
Alex Boten 3be58cff57
fix: update references to logging exporter (#1383)
This exporter has been replaced by the debug exporter and will be removed soon. Related to https://github.com/open-telemetry/opentelemetry-collector/pull/11037

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
2024-09-22 17:42:55 +10:00
Brett McBride 653e453f95
adding config provider (#1366)
implement recent additions to the otel spec re: config provider. Config provider should return a
ConfigProperties, but we were already returning a ConfigurationRegistry. Added a ConfigProperties
interface for ConfigurationRegistry to implement, which gets us pretty close to spec.
We don't make ConfigProvider globally available, instead passing the ConfigurationRegistry in to
each instrumentation as we register it. The spec allows for this.
2024-08-27 09:28:08 +10:00
Brett McBride 5276df3171
auto root span creation (#1354)
* auto root span creation
proof of concept for automatically creating a root span on startup.
the obvious deficiencies are:
- no idea of response values (status code etc)
- does not capture exceptions

* deptrac
2024-08-23 09:15:18 -04:00
Brett McBride 10b8d9732b
adding LocalRootSpan (#1310)
* adding LocalRootSpan class
this is based on Java's implementation, https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/v2.3.0/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/LocalRootSpan.java
and adds the ability to identify and locate the "local root span" in a trace. The local root span is the top-level active span which has either
an invalid or remote parent.
It's tracked automatically as part of making a span active, either via `Span::activate()` or `Span::storeInContext()`, and can be retrieved in
a couple of ways, but most easily via `LocalRootSpan::current()`.

* remove redundant local root span check

* move context key to api

* internal

* adding example

* mark LocalRootSpan as experimental

* adding an example of local root span usage

* style, fix broken build
2024-08-06 07:58:33 -04:00
Brett McBride 68b1b43cab
auto-instrumentation registration (#1304)
* [WIP] Add instrumentation configuration

* add autoloading for auto-instrumentations using SPI

* allow autoloading and non-autoloading to work

* fix attribute

* experimental config file

* fixing invalid dependencies
- deptrac was rightly complaining that API (indirectly) depended on SDK through config/sdk. For now,
remove usage of Config\SDK\Configuration\Context
- update deptrac config to allow some new dependencies

* dont register hook manager globally or in sdk

* remove unused function, psalm ignore missing extension function

* possibly fixing type-hint
psalm doesn't complain now, so that should be good

* load config files relative to cwd

* fixing hook manager enable/disable + psalm complaints

* fixing 8.1 psalm error

* use context to pass providers to instrumentations
- make "register global" a function of Sdk, but keep the sdk builder's interface intact
- invent an API instrumentation context, similar to the one in config/sdk, to pass providers
  to instrumentations
- add an initial test of autoloading from a config file

* adding tests for sdk::registerGlobal
in passing, remove some dead code for handling invalid booleans - config already handles this correctly

* linting

* test coverage for globals

* add opentelemetry extension to developer image and actions

* always register instrumentations via SPI

* register globals initializer for file-config sdk
allow SDK created from config file to coexist with components using globals initializer

* linting

* remove globals init function

* fix phan warning

* simplify hook manager
- drop storage from hook manager: can't guarantee that something else, eg swoole, won't modify storage
- drop context from hook manager: we must lazy-load globals via initializers, because not all instrumentations use SPI (although that may change in future)
- default hook manager to enabled

* add todo to deprecate Registry in future

* autoload instrumentations without config
if no config provided, still try to load them. wrap registration in a try/catch/log

* fixing phan ref, update doc

* remove phan suppress

* fix example

* bump SPI to 0.2.1

* adding late-binding tracer+provider
per review from Nevay, this will allow instrumentations to get things from Globals as late as possible

* adding late binding logger and meter providers

* more late binding test coverage

* tidy

* dont use CoversMethod yet
not available in phpunit 10, so comment out and leave a todo

* kitchen sink, remove unused var

* instrumentation config as a map, per config file spec

* adding general config

* move general config into sdk

* test config caching

* move general instrumentation config to api

* avoid bad version of sebastian/exporter

* bump config yaml files to 0.3

* fix tests

* disable hook manager during file-based init

* cleanup

* support multiple config files in autoloader

* move hook manager enable/disable out of extension hook manager
The most obvious place to do this is in a class named HookManager, which _was_ an
interface for hook managers. Rename existing HookManager to HookManagerInterface,
then re-purpose HookManager for globally enabling/disabling hook managers as well
as determining the disabled status.

* update spi config

---------

Co-authored-by: Tobias Bachert <git@b-privat.de>
2024-07-22 10:40:34 -04:00
Brett McBride a90f18cc72
event logger spec compliance (#1335)
update event logger to conform to spec 1.34.0:
- implement ForceFlush, which delegates to the LoggerProvider
- rename event payload to body
2024-06-26 15:34:36 +10:00
Brett McBride 500f6ee1bd
implement events v1.32 (#1291)
* implement events v1.32
implement the events api + sdk per spec v1.32:
- event logger is now only retrievable via an event logger provider
- domain attribute for events is removed
- events accept a subset of logrecord params, rather than an entire logrecord

* convert severity to a backed enum

* lint

* remove instead of deprecating logEvent, mark Logger constructor as internal

* make severity an enum only

* event attributes to iterable

* inject ClockInterface, add CachedInstrumentation, update examples

* set correct defaults for events

* test coverage

* Revert "make severity an enum only"

This reverts commit 710822907b.
Also, move PSR-3 mapping into the Severity enum.

* event attributes to iterable

* apply review feedback
2024-05-05 18:35:19 -04:00
Dalibor Karlović 5747fac40c
fix: correct path to autoloader in metrics/getting-started (#1299) 2024-04-30 20:51:20 +10:00
Brett McBride fc161a8548
migrate Clock classes to API (#1281)
* migrate Clock classes to API
- move Clock* + Util into API
- add a deprecated wrapper for ClockFactory and Util
- remove unused StopWatch* classes

* review feedback

* replace ClockFactory with Clock
It's not really a factory, and really only provides access to a system clock. Create a
Clock class which is more clear in its purpose.

* remove time Util class
per review feedback, it's only used in Zipkin. Removed some unused consts from ClockInterface

* Apply suggestions from code review

Co-authored-by: Tobias Bachert <git@b-privat.de>

---------

Co-authored-by: Tobias Bachert <git@b-privat.de>
2024-04-29 10:28:06 +10:00
Brett McBride 5a395e09da
enable timeout for http transports (#1275)
* enable timeout for http transports
Attempt to do our own discovery for some well-known PSR-18 clients, which allows
for configuring timeout (and in future certificates, keys etc).
This is not complete and a prototype for feedback, but I've updated an example to
show that it works for Guzzle and Symfony http clients

* improve client discovery

* refactor, test, add more implementations

* add timeout for logs and metrics
2024-04-25 16:21:00 +10:00
Tobias Bachert 7ec0e90402
File configuration (#1249)
* Add configuration model
* Add metrics and logs configuration model
* Remove accidentally added package dependency
* Fix `$properties` typehint to match config
Default value available -> cannot be null.
* Add configuration example that utilizes env substitution
* Fix/suppress config psalm issues
* Fix/suppress config phpstan issues
* Suppress config phan issues
* Apply cs-fixer
* Change config package version to development version 0.x
* Add README
* Add basic test
* Fix psalm and cs
* Fix composer requirement for PRs
* gitsplit, copy spi config to root composer.json
2024-04-01 18:13:01 +11:00
Brett McBride bb07aca7a2
upgrade psalm to v5 (#1246) 2024-03-04 06:58:09 -05:00
Brett McBride f798bb6f01
Drop PHP 7.4 support (#1244)
* drop php 7.4 support
update composer.json minimums, and run rector over the code to update what it can. changed some static analysis
config to fix some rector-induced failures.

* adding union typehints

* reformat constructor property promotions

* updating/removing phpdoc

* suppress protobuf extension complaint
submitted a PR upstream to fix phan stubs

* don't validate packages against 7.4

* remove php8 polyfill

* fix readonly comments

* apply trailing commas to multiline fixer
upgrade php-cs-fixer, and apply a new rule for multiline comments

* remove unreachable default match arms for protobuf serializer

* adding more union types to vars

* use weakmap directly

* remove handling for not-supported WeakMap

* spacing
2024-03-03 20:21:16 -05:00
Brett McBride 36e2b7f613
adding OTEL_PHP_EXCLUDED_URLS (#1226)
Modeled on python's feature to turn off all instrumentation for specific URLs,
https://opentelemetry.io/docs/languages/python/automatic/agent-config/#excluded-urls
this feature will effectively disable SDK autoloading if there is a request URI that
matches one of the provided excluded URLs, and no-op implementations will be used
for tracer/logger/meter providers.
2024-02-01 08:21:30 -05:00
Weslen Teche ea86fe1891
fix: documentations links (#1125) 2023-10-13 11:48:23 +11:00
Brett McBride 1852d514ca
fixing some psalm 5 complaints (#1110)
Whilst investigating upgrading to psalm 5, I notice that it generates a lot of new complaints. This fixes the ones that looked legit and
require an API change, or were trivial. Does not upgrade to psalm 5 yet, though. That's a bigger job for another day.
2023-09-05 08:56:24 +10:00
Brett McBride 73ff5adcb8
refactor sdk/api logging (#1105)
send errors/warnings/etc by default through PHP's error_log. This gives more control to administrators, since error_log can
be configured to write to any stream (file, stderr, etc). I think it's also less surprising for people trying out otel (particularly
with development PHP settings, where trigger_error often breaks an application).
Adding a configuration value to control where logs go: OTEL_PHP_LOG_DESTINATION.
2023-08-31 09:39:33 +10:00
Brett McBride 197a7a4c2c
optional internal metrics (#1106)
adding a configuration option OTEL_PHP_INTERNAL_METRICS_ENABLED which
controls whether the SDK will emit its own metrics (eg batch processor
state).
2023-08-31 09:23:20 +10:00
Brett McBride 55c08f3f44
adding PushMetricExporterInterface (#1097)
https://github.com/open-telemetry/opentelemetry-specification/pull/3563 clarifies the behaviour of
forceFlush with push/non-push metric exporters.
Break forceFlush out into a PushMetricExporterInterface, and update ExportingReader to only collect/flush
if exporter is a push metric exporter.
2023-08-10 07:47:46 +10:00
Tobias Bachert 926f6e5583
Always weaken asynchronous callbacks (#1081)
* Always weaken asynchronous callbacks
* Update comment regarding weak callbacks
2023-07-17 08:42:06 +10:00
Brett McBride a60d0ad80c
rename log record processors (#1073)
per TC review, align log record processor names with those used in the spec
2023-07-11 09:37:28 +10:00
Brett McBride 5853adabf1
phpdocs and example of weakening metric observer (#1078) 2023-07-11 09:36:04 +10:00
Brett McBride 3246ca8e4d
set schemaUrl for logs output (#1071) 2023-07-11 09:26:40 +10:00
Brett McBride 5e827ab7fc
improve logs console output (#1060)
support multiple scopes in console log output, and update batch example to illustrate
2023-07-04 14:46:57 +10:00
Brett McBride a0601c41ec
adding sdk console metrics exporter (#1055)
to make getting started easier (in opentelemetry.io docs), create an sdk-based metrics
exporter. this means we can export all signals without needing a protobuf implementation.
since console export is only useful for playing around, the change in format to a
simpler human-readable output seems reasonable.
2023-06-26 20:59:08 +10:00
Brett McBride 8fe898bdb4
adding batch span processor builder (#1046) 2023-06-23 10:22:49 +10:00
Brett McBride 1aea1f23b9
moving api/common classes up to api (#1033)
- apply TC review feedback to move Globals to top-level.
it was suggested to move Instrumentation into its own package, but I chose instead to just move that dir
up to the top level of API
- added a BC layer to alias the moved classes
- added some more examples
2023-06-16 08:51:03 +10:00
Brett McBride 22542528af
adding meter provider builder example (#1026)
adding an example using the meter provider builder, and deprecating a redundant method, `registerMetricReader`
2023-06-09 09:32:18 +10:00
Brett McBride 23cc194da1
psalm check examples (#1006)
Configure psalm to run over all examples, and fixing the issues it identified.
2023-05-31 08:13:35 +02:00
Brett McBride 1b63a3b1c3
adding console metric exporter (#1005)
allow the existing metric exporter to be created from env vars, by creating a factory
and registering it against 'console'. Now, OTEL_METRICS_EXPORTER=console will create
a metrics provider with console output. Note that it lives in contrib/otlp, since it
uses the existing otlp converters.
2023-05-17 10:41:55 +10:00
Brett McBride 5d35c998e7
remove proprietary new relic exporters (#998)
New Relic now fully supports OTLP ingestion, and having proprietary exporters is no longer their strategy. The proprietary exporters have been marked as abandoned in packagist, and suggest exporter-otlp as a replacement.
2023-05-09 20:20:50 +10:00
Brett McBride 593fa344bc
removing prometheus example (#996)
the example is very old, does not work, and it doesn't look like the capability
is in the spec these days. Remove the code so that it doesn't cause confusion.
2023-05-08 19:51:22 +10:00
Brett McBride bd02259089
resourceinfo spec compliance, instrumentation attribute (#989)
Introduce spec-compliant ResourceInfo::merge, and deprecate our current implementation.
When merging resources, later (updating) keys should override existing keys, per spec.
Reorganise detectors so that environment has highest priority (per spec, OTEL_SERVICE_NAME should be the highest priority built-in way of setting service name)
Adding the experimental telemetry.auto.version attribute, if the auto-instrumentation extension is installed.
2023-05-08 09:15:45 +10:00
Brett McBride c701693c25
remove 'include context' parameter from logging examples (#992)
the param was removed from spec, and our API implementation recently, but
I missed these examples.
2023-05-04 16:35:24 +02:00
Brett McBride 8f70a6d19f
apply logging spec updates (#977)
Removing include_trace_context parameter
Set ObservedTimestamp on emit if not already set
Rename logRecord to emit
2023-04-18 14:43:09 +02:00
Brett McBride a06e5e4e45
Multiple log processors (#967)
adding support for multiple log processors
2023-04-15 09:27:50 +10:00
Brett McBride c687df160d
report dropped counts in non-otel exporters (#966)
per spec, exporters MUST report on dropped attributes/links/events using keys defined in spec
2023-04-15 09:25:44 +10:00
Brett McBride e22007a98e
documenting logs bridge api, adding memory exporter (#959)
* implement bridge api

* adding logs memory exporter

* clarify bridge api not for developers

* adding logger provider builder

* review feedback

* removing Bridge and documenting what a bridge is
2023-04-12 08:06:41 -04:00
Brett McBride 502df0eded
adding LogRecord phpdocs (#956)
clarify that timestamps expect timestamp in nanoseconds, plus minor logging example fixes.
2023-04-05 22:42:42 +10:00