diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 8bd021faf..17fd261d0 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -13,11 +13,11 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['8.1', '8.2', '8.3'] + php-version: ['8.1', '8.2', '8.3', '8.4'] experimental: [false] composer_args: [""] include: - - php-version: 8.4 + - php-version: 8.5 experimental: true composer_args: "--ignore-platform-reqs" env: diff --git a/.github/workflows/phpdoc-to-github-pages b/.github/workflows/phpdoc-to-github-pages.yml similarity index 98% rename from .github/workflows/phpdoc-to-github-pages rename to .github/workflows/phpdoc-to-github-pages.yml index 69334e287..36648d157 100644 --- a/.github/workflows/phpdoc-to-github-pages +++ b/.github/workflows/phpdoc-to-github-pages.yml @@ -4,7 +4,6 @@ on: push: branches: - "main" - pull_request: workflow_dispatch: # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages diff --git a/README.md b/README.md index 2944e391b..10565533d 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ This is the **[monorepo](https://en.wikipedia.org/wiki/Monorepo)** for the **mai Please read the official documentation: https://opentelemetry.io/docs/instrumentation/php/ +API Documentation is available here: https://open-telemetry.github.io/opentelemetry-php/ + ## Packages and versions | Package | Latest | diff --git a/examples/load_config.yaml b/examples/load_config.yaml index d4d8d4de4..0535a6dbb 100644 --- a/examples/load_config.yaml +++ b/examples/load_config.yaml @@ -2,7 +2,9 @@ file_format: '0.3' resource: attributes: - service.name: opentelemetry-demo + - name: service.name + value: opentelemetry-demo + attributes_list: service.name=unused,example.foo=foo_value,example.bar=bar_value propagators: composite: [ tracecontext, baggage ] diff --git a/examples/load_config_env.yaml b/examples/load_config_env.yaml index b593419be..ba760b228 100644 --- a/examples/load_config_env.yaml +++ b/examples/load_config_env.yaml @@ -4,7 +4,8 @@ disabled: ${OTEL_SDK_DISABLED} resource: attributes: - service.name: ${OTEL_SERVICE_NAME} + - name: service.name + value: ${OTEL_SERVICE_NAME} propagators: composite: [ tracecontext, baggage ] diff --git a/proto/otel/composer.json b/proto/otel/composer.json index 1ee4865e8..95a701889 100644 --- a/proto/otel/composer.json +++ b/proto/otel/composer.json @@ -18,7 +18,7 @@ ], "require": { "php": "^8.0", - "google/protobuf": "^3.3.0" + "google/protobuf": "^3.22 || ^4.0" }, "autoload": { "psr-4": { diff --git a/src/API/Instrumentation/SpanAttribute.php b/src/API/Instrumentation/SpanAttribute.php index b2dcd1ef8..1a9fa1d13 100644 --- a/src/API/Instrumentation/SpanAttribute.php +++ b/src/API/Instrumentation/SpanAttribute.php @@ -11,7 +11,7 @@ * attribute, adding this attribute to an argument will * add the argument as a span attribute. */ -#[Attribute(Attribute::TARGET_PROPERTY)] +#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_PROPERTY)] final class SpanAttribute { /** diff --git a/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php b/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php index e9fbc09bf..ce1b1a571 100644 --- a/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php +++ b/src/Config/SDK/ComponentProvider/Logs/LogRecordExporterOtlp.php @@ -13,6 +13,7 @@ use OpenTelemetry\Contrib\Otlp\LogsExporter; use OpenTelemetry\Contrib\Otlp\OtlpUtil; use OpenTelemetry\Contrib\Otlp\Protocols; +use OpenTelemetry\SDK\Common\Configuration\Parser\MapParser; use OpenTelemetry\SDK\Logs\LogRecordExporterInterface; use OpenTelemetry\SDK\Registry; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; @@ -31,7 +32,7 @@ final class LogRecordExporterOtlp implements ComponentProvider * certificate: ?string, * client_key: ?string, * client_certificate: ?string, - * headers: array, + * headers: list, * headers_list: ?string, * compression: 'gzip'|null, * timeout: int<0, max>, @@ -42,10 +43,12 @@ public function createPlugin(array $properties, Context $context): LogRecordExpo { $protocol = $properties['protocol']; + $headers = array_column($properties['headers'], 'value', 'name') + MapParser::parse($properties['headers_list']); + return new LogsExporter(Registry::transportFactory($protocol)->create( endpoint: $properties['endpoint'] . OtlpUtil::path(Signals::LOGS, $protocol), contentType: Protocols::contentType($protocol), - headers: $properties['headers'], + headers: $headers, compression: $properties['compression'], timeout: $properties['timeout'], cacert: $properties['certificate'], diff --git a/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php b/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php index 72e177aef..42de4a759 100644 --- a/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php +++ b/src/Config/SDK/ComponentProvider/Metrics/MetricExporterOtlp.php @@ -13,6 +13,7 @@ use OpenTelemetry\Contrib\Otlp\MetricExporter; use OpenTelemetry\Contrib\Otlp\OtlpUtil; use OpenTelemetry\Contrib\Otlp\Protocols; +use OpenTelemetry\SDK\Common\Configuration\Parser\MapParser; use OpenTelemetry\SDK\Metrics\Data\Temporality; use OpenTelemetry\SDK\Metrics\MetricExporterInterface; use OpenTelemetry\SDK\Registry; @@ -32,7 +33,7 @@ final class MetricExporterOtlp implements ComponentProvider * certificate: ?string, * client_key: ?string, * client_certificate: ?string, - * headers: array, + * headers: list, * headers_list: ?string, * compression: 'gzip'|null, * timeout: int<0, max>, @@ -45,6 +46,8 @@ public function createPlugin(array $properties, Context $context): MetricExporte { $protocol = $properties['protocol']; + $headers = array_column($properties['headers'], 'value', 'name') + MapParser::parse($properties['headers_list']); + $temporality = match ($properties['temporality_preference']) { 'cumulative' => Temporality::CUMULATIVE, 'delta' => Temporality::DELTA, @@ -54,7 +57,7 @@ public function createPlugin(array $properties, Context $context): MetricExporte return new MetricExporter(Registry::transportFactory($protocol)->create( endpoint: $properties['endpoint'] . OtlpUtil::path(Signals::METRICS, $protocol), contentType: Protocols::contentType($protocol), - headers: $properties['headers'], + headers: $headers, compression: $properties['compression'], timeout: $properties['timeout'], cacert: $properties['certificate'], diff --git a/src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php b/src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php index 38a0aaa50..6200405e0 100644 --- a/src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php +++ b/src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php @@ -13,6 +13,7 @@ use OpenTelemetry\Context\Propagation\NoopTextMapPropagator; use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface; use OpenTelemetry\SDK\Common\Attribute\Attributes; +use OpenTelemetry\SDK\Common\Configuration\Parser\MapParser; use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeFactory; use OpenTelemetry\SDK\Logs\EventLoggerProvider; use OpenTelemetry\SDK\Logs\LoggerProvider; @@ -57,7 +58,10 @@ final class OpenTelemetrySdk implements ComponentProvider * resource: array{ * attributes: array, * attributes_list: ?string, +<<<<<<< HEAD * detectors: array, +======= +>>>>>>> main * schema_url: ?string, * }, * attribute_limits: array{ @@ -115,9 +119,7 @@ public function createPlugin(array $properties, Context $context): SdkBuilder if ($properties['disabled']) { return $sdkBuilder; } - - $attributes = array_column($properties['resource']['attributes'], 'value', 'name'); - + $attributes = array_column($properties['resource']['attributes'], 'value', 'name') + MapParser::parse($properties['resource']['attributes_list']); $resource = ResourceInfoFactory::defaultResource() ->merge(ResourceInfo::create( attributes: Attributes::create($attributes), @@ -292,6 +294,7 @@ private function getResourceConfig(): ArrayNodeDefinition ->children() ->scalarNode('name')->isRequired()->end() ->variableNode('value')->isRequired()->end() + // @todo use type to validate and/or cast attributes ->enumNode('type')->defaultNull() ->values(['string', 'bool', 'int', 'double', 'string_array', 'bool_array', 'int_array', 'double_array']) ->end() @@ -302,6 +305,7 @@ private function getResourceConfig(): ArrayNodeDefinition ->arrayNode('detectors') ->variablePrototype()->end() //todo types ->end() + ->scalarNode('attributes_list')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() ->scalarNode('schema_url')->defaultNull()->validate()->always(Validation::ensureString())->end()->end() ->end(); diff --git a/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php b/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php index 7d7235e9e..849c4fd6c 100644 --- a/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php +++ b/src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php @@ -13,6 +13,7 @@ use OpenTelemetry\Contrib\Otlp\OtlpUtil; use OpenTelemetry\Contrib\Otlp\Protocols; use OpenTelemetry\Contrib\Otlp\SpanExporter; +use OpenTelemetry\SDK\Common\Configuration\Parser\MapParser; use OpenTelemetry\SDK\Registry; use OpenTelemetry\SDK\Trace\SpanExporterInterface; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; @@ -31,7 +32,7 @@ final class SpanExporterOtlp implements ComponentProvider * certificate: ?string, * client_key: ?string, * client_certificate: ?string, - * headers: array, + * headers: list, * headers_list: ?string, * compression: 'gzip'|null, * timeout: int<0, max>, @@ -42,10 +43,12 @@ public function createPlugin(array $properties, Context $context): SpanExporterI { $protocol = $properties['protocol']; + $headers = array_column($properties['headers'], 'value', 'name') + MapParser::parse($properties['headers_list']); + return new SpanExporter(Registry::transportFactory($protocol)->create( endpoint: $properties['endpoint'] . OtlpUtil::path(Signals::TRACE, $protocol), contentType: Protocols::contentType($protocol), - headers: $properties['headers'], + headers: $headers, compression: $properties['compression'], timeout: $properties['timeout'], cacert: $properties['certificate'], diff --git a/src/SDK/Resource/Detectors/Host.php b/src/SDK/Resource/Detectors/Host.php index 7d74f6991..3a353cc67 100644 --- a/src/SDK/Resource/Detectors/Host.php +++ b/src/SDK/Resource/Detectors/Host.php @@ -54,7 +54,9 @@ private function getLinuxId(): ?string foreach ($paths as $path) { $file = $this->dir . $path; if (is_file($file) && is_readable($file)) { - return trim(file_get_contents($file)); + $contents = file_get_contents($file); + + return $contents !== false ? trim($contents) : null; } } @@ -65,7 +67,9 @@ private function getBsdId(): ?string { $file = $this->dir . self::PATH_ETC_HOSTID; if (is_file($file) && is_readable($file)) { - return trim(file_get_contents($file)); + $contents = file_get_contents($file); + + return $contents !== false ? trim($contents) : null; } $out = exec('which kenv && kenv -q smbios.system.uuid'); diff --git a/tests/Integration/Config/configurations/anchors.yaml b/tests/Integration/Config/configurations/anchors.yaml index 131f14c25..ea6121ac1 100644 --- a/tests/Integration/Config/configurations/anchors.yaml +++ b/tests/Integration/Config/configurations/anchors.yaml @@ -9,8 +9,8 @@ exporters: client_key: /app/cert.pem client_certificate: /app/cert.pem headers: - - name: "api-key" - value: "!!str 1234" + - name: api-key + value: "str 1234" compression: gzip timeout: 10000 diff --git a/tests/Integration/Config/configurations/kitchen-sink.yaml b/tests/Integration/Config/configurations/kitchen-sink.yaml index 74a21f753..2c08558fd 100644 --- a/tests/Integration/Config/configurations/kitchen-sink.yaml +++ b/tests/Integration/Config/configurations/kitchen-sink.yaml @@ -20,199 +20,171 @@ attribute_limits: # Configure logger provider. logger_provider: - # Configure log record processors. - processors: - - # Configure a batch log record processor. - batch: - # Configure delay interval (in milliseconds) between two consecutive exports. - schedule_delay: 5000 - # Configure maximum allowed time (in milliseconds) to export data. - export_timeout: 30000 - # Configure maximum queue size. - max_queue_size: 2048 - # Configure maximum batch size. - max_export_batch_size: 512 - # Configure exporter. - exporter: - # Configure exporter to be OTLP. - otlp: - # Configure protocol. - protocol: http/protobuf - # Configure endpoint. - endpoint: http://localhost:4318/v1/logs - # Configure certificate. - certificate: /app/cert.pem - # Configure mTLS private client key. - client_key: /app/cert.pem - # Configure mTLS client certificate. - client_certificate: /app/cert.pem - # Configure headers. Entries have higher priority than entries from .headers_list. - headers: - - name: api-key - value: "1234" - # Configure headers. Entries have lower priority than entries from .headers. - # The value is a list of comma separated key-value pairs matching the format of OTEL_EXPORTER_OTLP_HEADERS. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#configuration-options for details. - headers_list: "api-key=1234" - # Configure compression. - compression: gzip - # Configure max time (in milliseconds) to wait for each export. - timeout: 10000 - # Configure client transport security for the exporter's connection. - insecure: false - - # Configure a simple log record processor. - simple: - # Configure exporter. - exporter: - # Configure exporter to be console. - console: {} - # Configure log record limits. See also attribute_limits. - limits: - # Configure max attribute value size. Overrides .attribute_limits.attribute_value_length_limit. - attribute_value_length_limit: 4096 - # Configure max attribute count. Overrides .attribute_limits.attribute_count_limit. - attribute_count_limit: 128 + # Configure log record processors. + processors: + # Configure a batch log record processor. + - batch: + # Configure delay interval (in milliseconds) between two consecutive exports. + # + # Environment variable: OTEL_BLRP_SCHEDULE_DELAY + schedule_delay: 5000 + # Configure maximum allowed time (in milliseconds) to export data. + # + # Environment variable: OTEL_BLRP_EXPORT_TIMEOUT + export_timeout: 30000 + # Configure maximum queue size. + # + # Environment variable: OTEL_BLRP_MAX_QUEUE_SIZE + max_queue_size: 2048 + # Configure maximum batch size. + # + # Environment variable: OTEL_BLRP_MAX_EXPORT_BATCH_SIZE + max_export_batch_size: 512 + # Configure exporter. + # + # Environment variable: OTEL_LOGS_EXPORTER + exporter: + # Configure exporter to be OTLP. + otlp: + # Configure protocol. + # + # Environment variable: OTEL_EXPORTER_OTLP_PROTOCOL, OTEL_EXPORTER_OTLP_LOGS_PROTOCOL + protocol: http/protobuf + # Configure endpoint. + # + # Environment variable: OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_LOGS_ENDPOINT + endpoint: http://localhost:4318 + # Configure certificate. + # + # Environment variable: OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE + certificate: /app/cert.pem + # Configure mTLS private client key. + # + # Environment variable: OTEL_EXPORTER_OTLP_CLIENT_KEY, OTEL_EXPORTER_OTLP_LOGS_CLIENT_KEY + client_key: /app/cert.pem + # Configure mTLS client certificate. + # + # Environment variable: OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_LOGS_CLIENT_CERTIFICATE + client_certificate: /app/cert.pem + # Configure headers. Entries have higher priority than entries from .headers_list. + headers: + - name: api-key + value: "1234" + # Configure headers. Entries have lower priority than entries from .headers. + # The value is a list of comma separated key-value pairs matching the format of OTEL_EXPORTER_OTLP_HEADERS. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#configuration-options for details. + headers_list: "api-key=1234" + # Configure compression. + # + # Environment variable: OTEL_EXPORTER_OTLP_COMPRESSION, OTEL_EXPORTER_OTLP_LOGS_COMPRESSION + compression: gzip + # Configure max time (in milliseconds) to wait for each export. + # + # Environment variable: OTEL_EXPORTER_OTLP_TIMEOUT, OTEL_EXPORTER_OTLP_LOGS_TIMEOUT + timeout: 10000 + # Configure log record limits. See also attribute_limits. + limits: + # Configure max log record attribute value size. Overrides attribute_limits.attribute_value_length_limit. + # + # Environment variable: OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT + attribute_value_length_limit: 4096 + # Configure max log record attribute count. Overrides attribute_limits.attribute_count_limit. + # + # Environment variable: OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT + attribute_count_limit: 128 # Configure meter provider. meter_provider: - # Configure metric readers. - readers: - - # Configure a pull based metric reader. - pull: - # Configure exporter. - exporter: - # Configure exporter to be prometheus. - prometheus: - # Configure host. - host: localhost - # Configure port. - port: 9464 - # Configure Prometheus Exporter to produce metrics without a unit suffix or UNIT metadata. - without_units: false - # Configure Prometheus Exporter to produce metrics without a type suffix. - without_type_suffix: false - # Configure Prometheus Exporter to produce metrics without a scope info metric. - without_scope_info: false - # Configure Prometheus Exporter to add resource attributes as metrics attributes. - with_resource_constant_labels: - # Configure resource attributes to be included. If not set, no resource attributes are included. - # Attribute keys from resources are evaluated to match as follows: - # * If the value of the attribute key exactly matches. - # * If the value of the attribute key matches the wildcard pattern, where '?' matches any single character and '*' matches any number of characters including none. - included: - - "service*" - # Configure resource attributes to be excluded. Applies after .with_resource_constant_labels.included (i.e. excluded has higher priority than included). - # Attribute keys from resources are evaluated to match as follows: - # * If the value of the attribute key exactly matches. - # * If the value of the attribute key matches the wildcard pattern, where '?' matches any single character and '*' matches any number of characters including none. - excluded: - - "service.attr1" - # Configure metric producers. - producers: - - # Configure metric producer to be opencensus. - opencensus: {} - - # Configure a periodic metric reader. - periodic: - # Configure delay interval (in milliseconds) between start of two consecutive exports. - interval: 5000 - # Configure maximum allowed time (in milliseconds) to export data. - timeout: 30000 - # Configure exporter. - exporter: - # Configure exporter to be OTLP. - otlp: - # Configure protocol. - protocol: http/protobuf - # Configure endpoint. - endpoint: http://localhost:4318/v1/metrics - # Configure certificate. - certificate: /app/cert.pem - # Configure mTLS private client key. - client_key: /app/cert.pem - # Configure mTLS client certificate. - client_certificate: /app/cert.pem - # Configure headers. Entries have higher priority than entries from .headers_list. - headers: - - name: api-key - value: "1234" - # Configure headers. Entries have lower priority than entries from .headers. - # The value is a list of comma separated key-value pairs matching the format of OTEL_EXPORTER_OTLP_HEADERS. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#configuration-options for details. - headers_list: "api-key=1234" - # Configure compression. - compression: gzip - # Configure max time (in milliseconds) to wait for each export. - timeout: 10000 - # Configure client transport security for the exporter's connection. - insecure: false - # Configure temporality preference. - temporality_preference: delta - # Configure default histogram aggregation. - default_histogram_aggregation: base2_exponential_bucket_histogram - # Configure metric producers. - producers: - - # Configure metric producer to be prometheus. - prometheus: {} - - # Configure a periodic metric reader. - periodic: - # Configure exporter. - exporter: - # Configure exporter to be console. - console: {} - # Configure views. Each view has a selector which determines the instrument(s) it applies to, and a configuration for the resulting stream(s). - views: - - # Configure view selector. - selector: - # Configure instrument name selection criteria. - instrument_name: my-instrument - # Configure instrument type selection criteria. - instrument_type: histogram - # Configure the instrument unit selection criteria. - unit: ms - # Configure meter name selection criteria. - meter_name: my-meter - # Configure meter version selection criteria. - meter_version: 1.0.0 - # Configure meter schema url selection criteria. - meter_schema_url: https://opentelemetry.io/schemas/1.27.0 - # Configure view stream. - stream: - # Configure metric name of the resulting stream(s). - name: new_instrument_name - # Configure metric description of the resulting stream(s). - description: new_description - # Configure aggregation of the resulting stream(s). Known values include: default, drop, explicit_bucket_histogram, base2_exponential_bucket_histogram, last_value, sum. - aggregation: - # Configure aggregation to be explicit_bucket_histogram. - explicit_bucket_histogram: - # Configure bucket boundaries. - boundaries: - [ - 0.0, - 5.0, - 10.0, - 25.0, - 50.0, - 75.0, - 100.0, - 250.0, - 500.0, - 750.0, - 1000.0, - 2500.0, - 5000.0, - 7500.0, - 10000.0 - ] - # Configure record min and max. - record_min_max: true - # Configure attribute keys retained in the resulting stream(s). - attribute_keys: - # Configure list of attribute keys to include in the resulting stream(s). All other attributes are dropped. If not set, stream attributes are not configured. - included: - - key1 - - key2 - # Configure list of attribute keys to exclude from the resulting stream(s). Applies after .attribute_keys.included (i.e. excluded has higher priority than included). - excluded: - - key3 + # Configure metric readers. + readers: + # Configure a periodic metric reader. + - periodic: + # Configure delay interval (in milliseconds) between start of two consecutive exports. + # + # Environment variable: OTEL_METRIC_EXPORT_INTERVAL + interval: 5000 + # Configure maximum allowed time (in milliseconds) to export data. + # + # Environment variable: OTEL_METRIC_EXPORT_TIMEOUT + timeout: 30000 + # Configure exporter. + # + # Environment variable: OTEL_METRICS_EXPORTER + exporter: + # Configure exporter to be OTLP. + otlp: + # Configure protocol. + # + # Environment variable: OTEL_EXPORTER_OTLP_PROTOCOL, OTEL_EXPORTER_OTLP_METRICS_PROTOCOL + protocol: http/protobuf + # Configure endpoint. + # + # Environment variable: OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_METRICS_ENDPOINT + endpoint: http://localhost:4318 + # Configure certificate. + # + # Environment variable: OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE + certificate: /app/cert.pem + # Configure mTLS private client key. + # + # Environment variable: OTEL_EXPORTER_OTLP_CLIENT_KEY, OTEL_EXPORTER_OTLP_METRICS_CLIENT_KEY + client_key: /app/cert.pem + # Configure mTLS client certificate. + # + # Environment variable: OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATE + client_certificate: /app/cert.pem + # Configure headers. Entries have higher priority than entries from .headers_list. + headers: + - name: api-key + value: "1234" + # Configure headers. Entries have lower priority than entries from .headers. + # The value is a list of comma separated key-value pairs matching the format of OTEL_EXPORTER_OTLP_HEADERS. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#configuration-options for details. + headers_list: "api-key=1234" + # Configure compression. + # + # Environment variable: OTEL_EXPORTER_OTLP_COMPRESSION, OTEL_EXPORTER_OTLP_METRICS_COMPRESSION + compression: gzip + # Configure max time (in milliseconds) to wait for each export. + # + # Environment variable: OTEL_EXPORTER_OTLP_TIMEOUT, OTEL_EXPORTER_OTLP_METRICS_TIMEOUT + timeout: 10000 + # Configure temporality preference. + # + # Environment variable: OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE + temporality_preference: delta + # Configure a periodic metric reader. + - periodic: + # Configure exporter. + exporter: + # Configure exporter to be console. + console: {} + # Configure views. Each view has a selector which determines the instrument(s) it applies to, and a configuration for the resulting stream(s). + views: + # Configure a view. + - selector: + # Configure instrument name selection criteria. + instrument_name: my-instrument + # Configure instrument type selection criteria. + instrument_type: histogram + # Configure the instrument unit selection criteria. + unit: ms + # Configure meter name selection criteria. + meter_name: my-meter + # Configure meter version selection criteria. + meter_version: 1.0.0 + # Configure meter schema url selection criteria. + meter_schema_url: https://opentelemetry.io/schemas/1.16.0 + # Configure stream. + stream: + # Configure metric name of the resulting stream(s). + name: new_instrument_name + # Configure metric description of the resulting stream(s). + description: new_description + # Configure aggregation of the resulting stream(s). Known values include: default, drop, explicit_bucket_histogram, base2_exponential_bucket_histogram, last_value, sum. + aggregation: ~ + # Configure attribute keys retained in the resulting stream(s). + attribute_keys: + - key1 + - key2 # Configure text map context propagators. propagator: @@ -221,154 +193,184 @@ propagator: # Configure tracer provider. tracer_provider: - # Configure span processors. - processors: - - # Configure a batch span processor. - batch: - # Configure delay interval (in milliseconds) between two consecutive exports. - schedule_delay: 5000 - # Configure maximum allowed time (in milliseconds) to export data. - export_timeout: 30000 - # Configure maximum queue size. - max_queue_size: 2048 - # Configure maximum batch size. - max_export_batch_size: 512 - # Configure exporter. - exporter: - # Configure exporter to be OTLP. - otlp: - # Configure protocol. - protocol: http/protobuf - # Configure endpoint. - endpoint: http://localhost:4318/v1/traces - # Configure certificate. - certificate: /app/cert.pem - # Configure mTLS private client key. - client_key: /app/cert.pem - # Configure mTLS client certificate. - client_certificate: /app/cert.pem - # Configure headers. Entries have higher priority than entries from .headers_list. - headers: - - name: api-key - value: "1234" - # Configure headers. Entries have lower priority than entries from .headers. - # The value is a list of comma separated key-value pairs matching the format of OTEL_EXPORTER_OTLP_HEADERS. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#configuration-options for details. - headers_list: "api-key=1234" - # Configure compression. - compression: gzip - # Configure max time (in milliseconds) to wait for each export. - timeout: 10000 - # Configure client transport security for the exporter's connection. - insecure: false - - # Configure a batch span processor. - batch: - # Configure exporter. - exporter: - # Configure exporter to be zipkin. - zipkin: - # Configure endpoint. - endpoint: http://localhost:9411/api/v2/spans - # Configure max time (in milliseconds) to wait for each export. - timeout: 10000 - - # Configure a simple span processor. - simple: - # Configure exporter. - exporter: - # Configure exporter to be console. - console: {} - # Configure span limits. See also attribute_limits. - limits: - # Configure max attribute value size. Overrides .attribute_limits.attribute_value_length_limit. - attribute_value_length_limit: 4096 - # Configure max attribute count. Overrides .attribute_limits.attribute_count_limit. - attribute_count_limit: 128 - # Configure max span event count. - event_count_limit: 128 - # Configure max span link count. - link_count_limit: 128 - # Configure max attributes per span event. - event_attribute_count_limit: 128 - # Configure max attributes per span link. - link_attribute_count_limit: 128 - # Configure the sampler. - sampler: - # Configure sampler to be parent_based. - parent_based: - # Configure root sampler. - root: - # Configure sampler to be trace_id_ratio_based. - trace_id_ratio_based: - # Configure trace_id_ratio. - ratio: 0.0001 - # Configure remote_parent_sampled sampler. - remote_parent_sampled: - # Configure sampler to be always_on. - always_on: {} - # Configure remote_parent_not_sampled sampler. - remote_parent_not_sampled: - # Configure sampler to be always_off. - always_off: {} - # Configure local_parent_sampled sampler. - local_parent_sampled: - # Configure sampler to be always_on. - always_on: {} - # Configure local_parent_not_sampled sampler. - local_parent_not_sampled: - # Configure sampler to be always_off. - always_off: {} + # Configure span processors. + processors: + # Configure a batch span processor. + - batch: + # Configure delay interval (in milliseconds) between two consecutive exports. + # + # Environment variable: OTEL_BSP_SCHEDULE_DELAY + schedule_delay: 5000 + # Configure maximum allowed time (in milliseconds) to export data. + # + # Environment variable: OTEL_BSP_EXPORT_TIMEOUT + export_timeout: 30000 + # Configure maximum queue size. + # + # Environment variable: OTEL_BSP_MAX_QUEUE_SIZE + max_queue_size: 2048 + # Configure maximum batch size. + # + # Environment variable: OTEL_BSP_MAX_EXPORT_BATCH_SIZE + max_export_batch_size: 512 + # Configure exporter. + # + # Environment variable: OTEL_TRACES_EXPORTER + exporter: + # Configure exporter to be OTLP. + otlp: + # Configure protocol. + # + # Environment variable: OTEL_EXPORTER_OTLP_PROTOCOL, OTEL_EXPORTER_OTLP_TRACES_PROTOCOL + protocol: http/protobuf + # Configure endpoint. + # + # Environment variable: OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_ENDPOINT + endpoint: http://localhost:4318 + # Configure certificate. + # + # Environment variable: OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE + certificate: /app/cert.pem + # Configure mTLS private client key. + # + # Environment variable: OTEL_EXPORTER_OTLP_CLIENT_KEY, OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY + client_key: /app/cert.pem + # Configure mTLS client certificate. + # + # Environment variable: OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE + client_certificate: /app/cert.pem + # Configure headers. Entries have higher priority than entries from .headers_list. + headers: + - name: api-key + value: "1234" + # Configure headers. Entries have lower priority than entries from .headers. + # The value is a list of comma separated key-value pairs matching the format of OTEL_EXPORTER_OTLP_HEADERS. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#configuration-options for details. + headers_list: "api-key=1234" + # Configure compression. + # + # Environment variable: OTEL_EXPORTER_OTLP_COMPRESSION, OTEL_EXPORTER_OTLP_TRACES_COMPRESSION + compression: gzip + # Configure max time (in milliseconds) to wait for each export. + # + # Environment variable: OTEL_EXPORTER_OTLP_TIMEOUT, OTEL_EXPORTER_OTLP_TRACES_TIMEOUT + timeout: 10000 + # Configure a batch span processor. + - batch: + # Configure exporter. + # + # Environment variable: OTEL_TRACES_EXPORTER + exporter: + # Configure exporter to be zipkin. + zipkin: + # Configure endpoint. + # + # Environment variable: OTEL_EXPORTER_ZIPKIN_ENDPOINT + endpoint: http://localhost:9411/api/v2/spans + # Configure max time (in milliseconds) to wait for each export. + # + # Environment variable: OTEL_EXPORTER_ZIPKIN_TIMEOUT + timeout: 10000 + # Configure a simple span processor. + - simple: + # Configure exporter. + exporter: + # Configure exporter to be console. + console: {} + # Configure span limits. See also attribute_limits. + limits: + # Configure max span attribute value size. Overrides attribute_limits.attribute_value_length_limit. + # + # Environment variable: OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT + attribute_value_length_limit: 4096 + # Configure max span attribute count. Overrides attribute_limits.attribute_count_limit. + # + # Environment variable: OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT + attribute_count_limit: 128 + # Configure max span event count. + # + # Environment variable: OTEL_SPAN_EVENT_COUNT_LIMIT + event_count_limit: 128 + # Configure max span link count. + # + # Environment variable: OTEL_SPAN_LINK_COUNT_LIMIT + link_count_limit: 128 + # Configure max attributes per span event. + # + # Environment variable: OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT + event_attribute_count_limit: 128 + # Configure max attributes per span link. + # + # Environment variable: OTEL_LINK_ATTRIBUTE_COUNT_LIMIT + link_attribute_count_limit: 128 + # Configure the sampler. + sampler: + # Configure sampler to be parent_based. Known values include: always_off, always_on, jaeger_remote, parent_based, trace_id_ratio_based. + # + # Environment variable: OTEL_TRACES_SAMPLER=parentbased_* + parent_based: + # Configure root sampler. + # + # Environment variable: OTEL_TRACES_SAMPLER=parentbased_traceidratio + root: + # Configure sampler to be trace_id_ratio_based. + trace_id_ratio_based: + # Configure trace_id_ratio. + # + # Environment variable: OTEL_TRACES_SAMPLER_ARG=traceidratio=0.0001 + ratio: 0.0001 + # Configure remote_parent_sampled sampler. + remote_parent_sampled: + # Configure sampler to be always_on. + always_on: {} + # Configure remote_parent_not_sampled sampler. + remote_parent_not_sampled: + # Configure sampler to be always_off. + always_off: {} + # Configure local_parent_sampled sampler. + local_parent_sampled: + # Configure sampler to be always_on. + always_on: {} + # Configure local_parent_not_sampled sampler. + local_parent_not_sampled: + # Configure sampler to be always_off. + always_off: {} # Configure resource for all signals. resource: - # Configure resource attributes. Entries have higher priority than entries from .resource.attributes_list. - # Entries must contain .name nand .value, and may optionally include .type, which defaults ot "string" if not set. The value must match the type. Values for .type include: string, bool, int, double, string_array, bool_array, int_array, double_array. - attributes: - - name: service.name - value: unknown_service - - name: string_key - value: value - type: string - - name: bool_key - value: true - type: bool - - name: int_key - value: 1 - type: int - - name: double_key - value: 1.1 - type: double - - name: string_array_key - value: [ "value1", "value2" ] - type: string_array - - name: bool_array_key - value: [ true, false ] - type: bool_array - - name: int_array_key - value: [ 1, 2 ] - type: int_array - - name: double_array_key - value: [ 1.1, 2.2 ] - type: double_array - # Configure resource attributes. Entries have lower priority than entries from .resource.attributes. - # The value is a list of comma separated key-value pairs matching the format of OTEL_RESOURCE_ATTRIBUTES. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#general-sdk-configuration for details. - attributes_list: "service.namespace=my-namespace,service.version=1.0.0" - # Configure resource detectors. - detectors: - # Configure attributes provided by resource detectors. + # Configure resource attributes. Entries have higher priority than entries from .resource.attributes_list. + # Entries must contain .name nand .value, and may optionally include .type, which defaults ot "string" if not set. The value must match the type. Values for .type include: string, bool, int, double, string_array, bool_array, int_array, double_array. attributes: - # Configure list of attribute key patterns to include from resource detectors. If not set, all attributes are included. - # Attribute keys from resource detectors are evaluated to match as follows: - # * If the value of the attribute key exactly matches. - # * If the value of the attribute key matches the wildcard pattern, where '?' matches any single character and '*' matches any number of characters including none. - included: - - process.* - # Configure list of attribute key patterns to exclude from resource detectors. Applies after .resource.detectors.attributes.included (i.e. excluded has higher priority than included). - # Attribute keys from resource detectors are evaluated to match as follows: - # * If the value of the attribute key exactly matches. - # * If the value of the attribute key matches the wildcard pattern, where '?' matches any single character and '*' matches any number of characters including none. - excluded: - - process.command_args - # Configure resource schema URL. - schema_url: https://opentelemetry.io/schemas/1.27.0 + - name: service.name + value: unknown_service + - name: string_key + value: value + type: string + - name: bool_key + value: true + type: bool + - name: int_key + value: 1 + type: int + - name: double_key + value: 1.1 + type: double + - name: string_array_key + value: [ "value1", "value2" ] + type: string_array + - name: bool_array_key + value: [ true, false ] + type: bool_array + - name: int_array_key + value: [ 1, 2 ] + type: int_array + - name: double_array_key + value: [ 1.1, 2.2 ] + type: double_array + # Configure resource attributes. Entries have lower priority than entries from .resource.attributes. + # The value is a list of comma separated key-value pairs matching the format of OTEL_RESOURCE_ATTRIBUTES. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#general-sdk-configuration for details. + attributes_list: "service.namespace=my-namespace,service.version=1.0.0" + # Configure the resource schema URL. + schema_url: https://opentelemetry.io/schemas/1.27.0 # Configure instrumentation. instrumentation: diff --git a/tests/Unit/API/Instrumentation/SpanAttributeTest.php b/tests/Unit/API/Instrumentation/SpanAttributeTest.php index d6437aa82..cc905ecde 100644 --- a/tests/Unit/API/Instrumentation/SpanAttributeTest.php +++ b/tests/Unit/API/Instrumentation/SpanAttributeTest.php @@ -5,7 +5,9 @@ namespace OpenTelemetry\Tests\Unit\API\Instrumentation; use OpenTelemetry\API\Instrumentation\SpanAttribute; +use OpenTelemetry\API\Instrumentation\WithSpan; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\TestCase; #[CoversClass(SpanAttribute::class)] @@ -16,4 +18,17 @@ public function test_with_span(): void $attr = new SpanAttribute('foo'); $this->assertSame('foo', $attr->name); } + + #[DoesNotPerformAssertions] + public function test_attribute_targets_parameter(): void + { + new class() { + #[WithSpan] + public function foo( + #[SpanAttribute] string $a, + #[SpanAttribute('a_better_attribute_name')] string $b, + ): void { + } + }; + } }