Skip to content

Commit f06afb7

Browse files
authored
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.
1 parent 0946656 commit f06afb7

File tree

5 files changed

+46
-16
lines changed

5 files changed

+46
-16
lines changed

Common/Configuration/ConfigurationResolver.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ public function getList(string $name): array
3232
{
3333
return Configuration::getList($name);
3434
}
35+
36+
public function getEnum(string $name): ?string
37+
{
38+
return Configuration::getEnum($name);
39+
}
3540
}

Common/Configuration/Defaults.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,5 @@ interface Defaults
116116
public const OTEL_PHP_INTERNAL_METRICS_ENABLED = 'false';
117117
public const OTEL_PHP_DISABLED_INSTRUMENTATIONS = [];
118118
public const OTEL_PHP_LOGS_PROCESSOR = 'batch';
119+
public const OTEL_PHP_LOG_DESTINATION = 'default';
119120
}

Common/Configuration/KnownValues.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ interface KnownValues
172172
self::VALUE_NONE,
173173
];
174174
public const OTEL_PHP_AUTOLOAD_ENABLED = self::VALUES_BOOLEAN;
175+
public const VALUE_ERROR_LOG = 'error_log';
176+
public const VALUE_STDERR = 'stderr';
177+
public const VALUE_STDOUT = 'stdout';
178+
public const VALUE_PSR3 = 'psr3';
179+
public const VALUE_EMPTY = '';
175180
public const VALUE_DETECTORS_ENVIRONMENT = 'env';
176181
public const VALUE_DETECTORS_HOST = 'host';
177182
public const VALUE_DETECTORS_OS = 'os';
@@ -192,4 +197,12 @@ interface KnownValues
192197
self::VALUE_DETECTORS_COMPOSER,
193198
self::VALUE_NONE,
194199
];
200+
public const OTEL_PHP_LOG_DESTINATION = [
201+
self::VALUE_ERROR_LOG,
202+
self::VALUE_STDERR,
203+
self::VALUE_STDOUT,
204+
self::VALUE_PSR3,
205+
self::VALUE_EMPTY,
206+
self::VALUE_NONE,
207+
];
195208
}

Common/Configuration/ValueTypes.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface ValueTypes
1212
{
1313
/**
1414
* General SDK Configuration
15-
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#general-sdk-configuration
15+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/configuration/sdk-environment-variables.md#general-sdk-configuration
1616
*/
1717
public const OTEL_RESOURCE_ATTRIBUTES = VariableTypes::MAP;
1818
public const OTEL_SERVICE_NAME = VariableTypes::STRING;
@@ -22,38 +22,45 @@ interface ValueTypes
2222
public const OTEL_TRACES_SAMPLER_ARG = VariableTypes::MIXED;
2323
/**
2424
* Batch Span Processor
25-
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#batch-span-processor
25+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/configuration/sdk-environment-variables.md#batch-span-processor
2626
*/
2727
public const OTEL_BSP_SCHEDULE_DELAY = VariableTypes::INTEGER;
2828
public const OTEL_BSP_EXPORT_TIMEOUT = VariableTypes::INTEGER;
2929
public const OTEL_BSP_MAX_QUEUE_SIZE = VariableTypes::INTEGER;
3030
public const OTEL_BSP_MAX_EXPORT_BATCH_SIZE = VariableTypes::INTEGER;
3131
/**
3232
* Batch LogRecord Processor
33+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/configuration/sdk-environment-variables.md#batch-logrecord-processor
3334
*/
3435
public const OTEL_BLRP_SCHEDULE_DELAY = VariableTypes::INTEGER;
3536
public const OTEL_BLRP_EXPORT_TIMEOUT = VariableTypes::INTEGER;
3637
public const OTEL_BLRP_MAX_QUEUE_SIZE = VariableTypes::INTEGER;
3738
public const OTEL_BLRP_MAX_EXPORT_BATCH_SIZE = VariableTypes::INTEGER;
3839
/**
3940
* Attribute Limits
40-
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#attribute-limits
41+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/configuration/sdk-environment-variables.md#attribute-limits
4142
*/
4243
public const OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT = VariableTypes::INTEGER;
4344
public const OTEL_ATTRIBUTE_COUNT_LIMIT = VariableTypes::INTEGER;
4445
/**
4546
* Span Limits
46-
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#span-limits-
47+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/configuration/sdk-environment-variables.md#span-limits
4748
*/
4849
public const OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT = VariableTypes::INTEGER;
4950
public const OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT = VariableTypes::INTEGER;
5051
public const OTEL_SPAN_EVENT_COUNT_LIMIT = VariableTypes::INTEGER;
5152
public const OTEL_SPAN_LINK_COUNT_LIMIT = VariableTypes::INTEGER;
5253
public const OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT = VariableTypes::INTEGER;
5354
public const OTEL_LINK_ATTRIBUTE_COUNT_LIMIT = VariableTypes::INTEGER;
55+
/**
56+
* LogRecord Limits
57+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/configuration/sdk-environment-variables.md#logrecord-limits
58+
*/
59+
public const OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT = VariableTypes::INTEGER;
60+
public const OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT = VariableTypes::INTEGER;
5461
/**
5562
* OTLP Exporter
56-
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#configuration-options
63+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/protocol/exporter.md#configuration-options
5764
*/
5865
// Endpoint
5966
public const OTEL_EXPORTER_OTLP_ENDPOINT = VariableTypes::STRING;
@@ -117,8 +124,10 @@ interface ValueTypes
117124
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#language-specific-environment-variables
118125
*/
119126
public const OTEL_PHP_TRACES_PROCESSOR = VariableTypes::ENUM;
127+
public const OTEL_PHP_LOGS_PROCESSOR = VariableTypes::LIST;
120128
public const OTEL_PHP_DETECTORS = VariableTypes::LIST;
121129
public const OTEL_PHP_AUTOLOAD_ENABLED = VariableTypes::BOOL;
130+
public const OTEL_PHP_LOG_DESTINATION = VariableTypes::ENUM;
122131
public const OTEL_PHP_INTERNAL_METRICS_ENABLED = VariableTypes::BOOL;
123132
public const OTEL_PHP_DISABLED_INSTRUMENTATIONS = VariableTypes::LIST;
124133
}

Common/Configuration/Variables.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface Variables
1212
{
1313
/**
1414
* General SDK Configuration
15-
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#general-sdk-configuration
15+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/configuration/sdk-environment-variables.md#general-sdk-configuration
1616
*/
1717
public const OTEL_RESOURCE_ATTRIBUTES = 'OTEL_RESOURCE_ATTRIBUTES';
1818
public const OTEL_SERVICE_NAME = 'OTEL_SERVICE_NAME';
@@ -23,35 +23,35 @@ interface Variables
2323
public const OTEL_SDK_DISABLED = 'OTEL_SDK_DISABLED';
2424
/**
2525
* Batch Span Processor
26-
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#batch-span-processor
26+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/configuration/sdk-environment-variables.md#batch-span-processor
2727
*/
2828
public const OTEL_BSP_SCHEDULE_DELAY = 'OTEL_BSP_SCHEDULE_DELAY';
2929
public const OTEL_BSP_EXPORT_TIMEOUT = 'OTEL_BSP_EXPORT_TIMEOUT';
3030
public const OTEL_BSP_MAX_QUEUE_SIZE = 'OTEL_BSP_MAX_QUEUE_SIZE';
3131
public const OTEL_BSP_MAX_EXPORT_BATCH_SIZE = 'OTEL_BSP_MAX_EXPORT_BATCH_SIZE';
3232
/**
3333
* Batch LogRecord Processor
34-
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#batch-logrecord-processor
34+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/configuration/sdk-environment-variables.md#batch-logrecord-processor
3535
*/
3636
public const OTEL_BLRP_SCHEDULE_DELAY = 'OTEL_BLRP_SCHEDULE_DELAY';
3737
public const OTEL_BLRP_EXPORT_TIMEOUT = 'OTEL_BLRP_EXPORT_TIMEOUT';
3838
public const OTEL_BLRP_MAX_QUEUE_SIZE = 'OTEL_BLRP_MAX_QUEUE_SIZE';
3939
public const OTEL_BLRP_MAX_EXPORT_BATCH_SIZE = 'OTEL_BLRP_MAX_EXPORT_BATCH_SIZE';
4040
/**
4141
* Attribute Limits
42-
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#attribute-limits
42+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/configuration/sdk-environment-variables.md#attribute-limits
4343
*/
4444
public const OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT = 'OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT';
4545
public const OTEL_ATTRIBUTE_COUNT_LIMIT = 'OTEL_ATTRIBUTE_COUNT_LIMIT';
4646
/**
4747
* LogRecord limits
48-
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#logrecord-limits
48+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/configuration/sdk-environment-variables.md#logrecord-limits
4949
*/
5050
public const OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT = 'OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT';
5151
public const OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT = 'OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT';
5252
/**
5353
* Span Limits
54-
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#span-limits-
54+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/configuration/sdk-environment-variables.md#span-limits
5555
*/
5656
public const OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT = 'OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT';
5757
public const OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT = 'OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT';
@@ -61,7 +61,7 @@ interface Variables
6161
public const OTEL_LINK_ATTRIBUTE_COUNT_LIMIT = 'OTEL_LINK_ATTRIBUTE_COUNT_LIMIT';
6262
/**
6363
* OTLP Exporter
64-
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#configuration-options
64+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/protocol/exporter.md#configuration-options
6565
*/
6666
// Endpoint
6767
public const OTEL_EXPORTER_OTLP_ENDPOINT = 'OTEL_EXPORTER_OTLP_ENDPOINT';
@@ -100,27 +100,28 @@ interface Variables
100100
public const OTEL_EXPORTER_OTLP_LOGS_PROTOCOL = 'OTEL_EXPORTER_OTLP_LOGS_PROTOCOL';
101101
/**
102102
* Zipkin Exporter
103-
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#zipkin-exporter
103+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/configuration/sdk-environment-variables.md#zipkin-exporter
104104
*/
105105
public const OTEL_EXPORTER_ZIPKIN_ENDPOINT = 'OTEL_EXPORTER_ZIPKIN_ENDPOINT';
106106
public const OTEL_EXPORTER_ZIPKIN_TIMEOUT = 'OTEL_EXPORTER_ZIPKIN_TIMEOUT';
107107
public const OTEL_EXPORTER_ZIPKIN_PROTOCOL = 'OTEL_EXPORTER_ZIPKIN_PROTOCOL';
108108
/**
109109
* Prometheus Exporter
110-
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#prometheus-exporter
110+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/configuration/sdk-environment-variables.md#prometheus-exporter
111111
*/
112112
public const OTEL_EXPORTER_PROMETHEUS_HOST = 'OTEL_EXPORTER_PROMETHEUS_HOST';
113113
public const OTEL_EXPORTER_PROMETHEUS_PORT = 'OTEL_EXPORTER_PROMETHEUS_PORT';
114114
/**
115115
* Exporter Selection
116-
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#exporter-selection
116+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/configuration/sdk-environment-variables.md#exporter-selection
117117
*/
118118
public const OTEL_TRACES_EXPORTER = 'OTEL_TRACES_EXPORTER';
119119
public const OTEL_METRICS_EXPORTER = 'OTEL_METRICS_EXPORTER';
120120
public const OTEL_LOGS_EXPORTER = 'OTEL_LOGS_EXPORTER';
121121
/**
122122
* Metrics SDK Configuration
123-
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md#metrics-sdk-configuration
123+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/configuration/sdk-environment-variables.md#metrics-sdk-configuration
124+
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/configuration/sdk-environment-variables.md#periodic-exporting-metricreader
124125
*/
125126
public const OTEL_METRICS_EXEMPLAR_FILTER = 'OTEL_METRICS_EXEMPLAR_FILTER';
126127
public const OTEL_METRIC_EXPORT_INTERVAL = 'OTEL_METRIC_EXPORT_INTERVAL';
@@ -133,6 +134,7 @@ interface Variables
133134
*/
134135
public const OTEL_PHP_TRACES_PROCESSOR = 'OTEL_PHP_TRACES_PROCESSOR';
135136
public const OTEL_PHP_LOGS_PROCESSOR = 'OTEL_PHP_LOGS_PROCESSOR';
137+
public const OTEL_PHP_LOG_DESTINATION = 'OTEL_PHP_LOG_DESTINATION';
136138
public const OTEL_PHP_DETECTORS = 'OTEL_PHP_DETECTORS';
137139
public const OTEL_PHP_AUTOLOAD_ENABLED = 'OTEL_PHP_AUTOLOAD_ENABLED';
138140
public const OTEL_PHP_INTERNAL_METRICS_ENABLED = 'OTEL_PHP_INTERNAL_METRICS_ENABLED'; //whether the SDK should emit its own metrics

0 commit comments

Comments
 (0)