Skip to content

Commit

Permalink
Merge branch 'main' into config-0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
brettmc committed Dec 10, 2024
2 parents 367db2e + 4a021fb commit 9b0749e
Show file tree
Hide file tree
Showing 15 changed files with 392 additions and 354 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- "main"
pull_request:
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
4 changes: 3 additions & 1 deletion examples/load_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
3 changes: 2 additions & 1 deletion examples/load_config_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
2 changes: 1 addition & 1 deletion proto/otel/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"require": {
"php": "^8.0",
"google/protobuf": "^3.3.0"
"google/protobuf": "^3.22 || ^4.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/API/Instrumentation/SpanAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +32,7 @@ final class LogRecordExporterOtlp implements ComponentProvider
* certificate: ?string,
* client_key: ?string,
* client_certificate: ?string,
* headers: array,
* headers: list<array{name: string, value: string}>,
* headers_list: ?string,
* compression: 'gzip'|null,
* timeout: int<0, max>,
Expand All @@ -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'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,7 +33,7 @@ final class MetricExporterOtlp implements ComponentProvider
* certificate: ?string,
* client_key: ?string,
* client_certificate: ?string,
* headers: array,
* headers: list<array{name: string, value: string}>,
* headers_list: ?string,
* compression: 'gzip'|null,
* timeout: int<0, max>,
Expand All @@ -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,
Expand All @@ -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'],
Expand Down
10 changes: 7 additions & 3 deletions src/Config/SDK/ComponentProvider/OpenTelemetrySdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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()
Expand All @@ -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();

Expand Down
7 changes: 5 additions & 2 deletions src/Config/SDK/ComponentProvider/Trace/SpanExporterOtlp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +32,7 @@ final class SpanExporterOtlp implements ComponentProvider
* certificate: ?string,
* client_key: ?string,
* client_certificate: ?string,
* headers: array,
* headers: list<array{name: string, value: string}>,
* headers_list: ?string,
* compression: 'gzip'|null,
* timeout: int<0, max>,
Expand All @@ -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'],
Expand Down
8 changes: 6 additions & 2 deletions src/SDK/Resource/Detectors/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Config/configurations/anchors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit 9b0749e

Please sign in to comment.