From cdd7ad020e165fe680703b6d3319b908b682fb7a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 20 Oct 2023 17:12:29 +0300 Subject: jaeger-client -> opentelemetry --- .../Adapter/HttpDiscovery/DependencyResolver.php | 83 +++++ .../HttpDiscovery/HttpPlugClientResolver.php | 29 ++ .../HttpDiscovery/MessageFactoryResolver.php | 88 +++++ .../Adapter/HttpDiscovery/PsrClientResolver.php | 29 ++ .../sdk/Common/Attribute/AttributeValidator.php | 58 ++++ .../Attribute/AttributeValidatorInterface.php | 11 + .../sdk/Common/Attribute/Attributes.php | 67 ++++ .../sdk/Common/Attribute/AttributesBuilder.php | 120 +++++++ .../Attribute/AttributesBuilderInterface.php | 12 + .../sdk/Common/Attribute/AttributesFactory.php | 36 +++ .../Attribute/AttributesFactoryInterface.php | 10 + .../sdk/Common/Attribute/AttributesInterface.php | 19 ++ .../Common/Attribute/FilteredAttributesBuilder.php | 77 +++++ .../Common/Attribute/FilteredAttributesFactory.php | 33 ++ .../Attribute/LogRecordAttributeValidator.php | 19 ++ .../sdk/Common/Configuration/Configuration.php | 182 +++++++++++ .../sdk/Common/Configuration/Defaults.php | 122 +++++++ .../sdk/Common/Configuration/KnownValues.php | 208 ++++++++++++ .../Common/Configuration/Parser/BooleanParser.php | 34 ++ .../sdk/Common/Configuration/Parser/ListParser.php | 28 ++ .../sdk/Common/Configuration/Parser/MapParser.php | 45 +++ .../Common/Configuration/Parser/RatioParser.php | 38 +++ .../Configuration/Resolver/CompositeResolver.php | 68 ++++ .../Configuration/Resolver/EnvironmentResolver.php | 40 +++ .../Configuration/Resolver/PhpIniAccessor.php | 18 ++ .../Configuration/Resolver/PhpIniResolver.php | 41 +++ .../Configuration/Resolver/ResolverInterface.php | 15 + .../sdk/Common/Configuration/ValueTypes.php | 133 ++++++++ .../sdk/Common/Configuration/VariableTypes.php | 62 ++++ .../sdk/Common/Configuration/Variables.php | 142 ++++++++ .../sdk/Common/Dev/Compatibility/README.md | 14 + .../sdk/Common/Dev/Compatibility/Util.php | 93 ++++++ .../sdk/Common/Dev/Compatibility/_load.php | 7 + .../sdk/Common/Exception/StackTraceFormatter.php | 155 +++++++++ .../sdk/Common/Export/Http/PsrTransport.php | 168 ++++++++++ .../sdk/Common/Export/Http/PsrTransportFactory.php | 74 +++++ .../sdk/Common/Export/Http/PsrUtils.php | 175 ++++++++++ .../sdk/Common/Export/Stream/StreamTransport.php | 97 ++++++ .../Export/Stream/StreamTransportFactory.php | 118 +++++++ .../Common/Export/TransportFactoryInterface.php | 32 ++ .../sdk/Common/Export/TransportInterface.php | 22 ++ .../sdk/Common/Future/CancellationInterface.php | 18 ++ .../sdk/Common/Future/CompletedFuture.php | 48 +++ .../sdk/Common/Future/ErrorFuture.php | 40 +++ .../sdk/Common/Future/FutureInterface.php | 34 ++ .../sdk/Common/Future/NullCancellation.php | 20 ++ .../Common/Http/DependencyResolverInterface.php | 13 + .../Http/HttpPlug/Client/ResolverInterface.php | 12 + .../Common/Http/Psr/Client/ResolverInterface.php | 12 + .../Http/Psr/Message/FactoryResolverInterface.php | 22 ++ .../sdk/Common/Http/Psr/Message/MessageFactory.php | 52 +++ .../Http/Psr/Message/MessageFactoryInterface.php | 13 + .../Instrumentation/InstrumentationScope.php | 46 +++ .../InstrumentationScopeFactory.php | 31 ++ .../InstrumentationScopeFactoryInterface.php | 15 + .../InstrumentationScopeInterface.php | 18 ++ .../sdk/Common/Time/ClockFactory.php | 30 ++ .../sdk/Common/Time/ClockFactoryInterface.php | 16 + .../sdk/Common/Time/ClockInterface.php | 19 ++ .../open-telemetry/sdk/Common/Time/StopWatch.php | 119 +++++++ .../sdk/Common/Time/StopWatchFactory.php | 44 +++ .../sdk/Common/Time/StopWatchFactoryInterface.php | 18 ++ .../sdk/Common/Time/StopWatchInterface.php | 20 ++ .../open-telemetry/sdk/Common/Time/SystemClock.php | 49 +++ vendor/open-telemetry/sdk/Common/Time/Util.php | 32 ++ .../sdk/Common/Util/ClassConstantAccessor.php | 35 ++ .../sdk/Common/Util/ShutdownHandler.php | 82 +++++ vendor/open-telemetry/sdk/Common/Util/WeakMap.php | 175 ++++++++++ .../open-telemetry/sdk/Common/Util/functions.php | 52 +++ .../sdk/Logs/Exporter/ConsoleExporter.php | 106 ++++++ .../sdk/Logs/Exporter/ConsoleExporterFactory.php | 19 ++ .../sdk/Logs/Exporter/InMemoryExporter.php | 48 +++ .../sdk/Logs/Exporter/InMemoryExporterFactory.php | 16 + .../sdk/Logs/Exporter/NoopExporter.php | 28 ++ .../open-telemetry/sdk/Logs/Exporter/_register.php | 6 + vendor/open-telemetry/sdk/Logs/ExporterFactory.php | 29 ++ .../sdk/Logs/LogRecordExporterFactoryInterface.php | 10 + .../sdk/Logs/LogRecordExporterInterface.php | 18 ++ vendor/open-telemetry/sdk/Logs/LogRecordLimits.php | 29 ++ .../sdk/Logs/LogRecordLimitsBuilder.php | 58 ++++ .../sdk/Logs/LogRecordProcessorFactory.php | 62 ++++ .../sdk/Logs/LogRecordProcessorInterface.php | 15 + vendor/open-telemetry/sdk/Logs/Logger.php | 37 +++ vendor/open-telemetry/sdk/Logs/LoggerProvider.php | 56 ++++ .../sdk/Logs/LoggerProviderBuilder.php | 55 ++++ .../sdk/Logs/LoggerProviderFactory.php | 24 ++ .../sdk/Logs/LoggerProviderInterface.php | 13 + .../open-telemetry/sdk/Logs/LoggerSharedState.php | 60 ++++ .../open-telemetry/sdk/Logs/NoopLoggerProvider.php | 33 ++ .../sdk/Logs/Processor/BatchLogRecordProcessor.php | 273 ++++++++++++++++ .../sdk/Logs/Processor/MultiLogRecordProcessor.php | 62 ++++ .../sdk/Logs/Processor/NoopLogRecordProcessor.php | 37 +++ .../Logs/Processor/SimpleLogRecordProcessor.php | 38 +++ .../sdk/Logs/PsrSeverityMapperInterface.php | 50 +++ .../open-telemetry/sdk/Logs/ReadWriteLogRecord.php | 9 + .../open-telemetry/sdk/Logs/ReadableLogRecord.php | 103 ++++++ .../sdk/Logs/SimplePsrFileLogger.php | 83 +++++ .../ExplicitBucketHistogramAggregation.php | 167 ++++++++++ .../Aggregation/ExplicitBucketHistogramSummary.php | 40 +++ .../Metrics/Aggregation/LastValueAggregation.php | 81 +++++ .../sdk/Metrics/Aggregation/LastValueSummary.php | 22 ++ .../sdk/Metrics/Aggregation/SumAggregation.php | 91 ++++++ .../sdk/Metrics/Aggregation/SumSummary.php | 20 ++ .../sdk/Metrics/AggregationInterface.php | 57 ++++ .../AggregationTemporalitySelectorInterface.php | 21 ++ .../FilteredAttributeProcessor.php | 33 ++ .../IdentityAttributeProcessor.php | 20 ++ .../sdk/Metrics/AttributeProcessorInterface.php | 16 + vendor/open-telemetry/sdk/Metrics/Counter.php | 37 +++ .../sdk/Metrics/Data/DataInterface.php | 9 + .../open-telemetry/sdk/Metrics/Data/Exemplar.php | 65 ++++ vendor/open-telemetry/sdk/Metrics/Data/Gauge.php | 22 ++ .../open-telemetry/sdk/Metrics/Data/Histogram.php | 29 ++ .../sdk/Metrics/Data/HistogramDataPoint.php | 76 +++++ vendor/open-telemetry/sdk/Metrics/Data/Metric.php | 46 +++ .../sdk/Metrics/Data/NumberDataPoint.php | 43 +++ vendor/open-telemetry/sdk/Metrics/Data/Sum.php | 34 ++ .../sdk/Metrics/Data/Temporality.php | 20 ++ .../DefaultAggregationProviderInterface.php | 13 + .../Metrics/DefaultAggregationProviderTrait.php | 28 ++ .../sdk/Metrics/Exemplar/BucketEntry.php | 26 ++ .../sdk/Metrics/Exemplar/BucketStorage.php | 92 ++++++ .../Exemplar/ExemplarFilter/AllExemplarFilter.php | 21 ++ .../Exemplar/ExemplarFilter/NoneExemplarFilter.php | 21 ++ .../WithSampledTraceExemplarFilter.php | 22 ++ .../Metrics/Exemplar/ExemplarFilterInterface.php | 20 ++ .../Exemplar/ExemplarReservoirInterface.php | 24 ++ .../sdk/Metrics/Exemplar/FilteredReservoir.php | 36 +++ .../sdk/Metrics/Exemplar/FixedSizeReservoir.php | 38 +++ .../Metrics/Exemplar/HistogramBucketReservoir.php | 40 +++ .../sdk/Metrics/Exemplar/NoopReservoir.php | 21 ++ vendor/open-telemetry/sdk/Metrics/Histogram.php | 37 +++ vendor/open-telemetry/sdk/Metrics/Instrument.php | 36 +++ .../open-telemetry/sdk/Metrics/InstrumentType.php | 25 ++ vendor/open-telemetry/sdk/Metrics/Meter.php | 314 ++++++++++++++++++ .../sdk/Metrics/MeterInstruments.php | 29 ++ .../open-telemetry/sdk/Metrics/MeterProvider.php | 130 ++++++++ .../sdk/Metrics/MeterProviderBuilder.php | 62 ++++ .../sdk/Metrics/MeterProviderFactory.php | 78 +++++ .../sdk/Metrics/MeterProviderInterface.php | 12 + .../MetricExporter/ConsoleMetricExporter.php | 105 ++++++ .../ConsoleMetricExporterFactory.php | 16 + .../Metrics/MetricExporter/InMemoryExporter.php | 78 +++++ .../MetricExporter/InMemoryExporterFactory.php | 16 + .../Metrics/MetricExporter/NoopMetricExporter.php | 23 ++ .../MetricExporter/NoopMetricExporterFactory.php | 16 + .../sdk/Metrics/MetricExporter/_register.php | 7 + .../sdk/Metrics/MetricExporterFactoryInterface.php | 10 + .../sdk/Metrics/MetricExporterInterface.php | 17 + .../sdk/Metrics/MetricFactory/StreamFactory.php | 187 +++++++++++ .../Metrics/MetricFactory/StreamMetricSource.php | 44 +++ .../MetricFactory/StreamMetricSourceProvider.php | 98 ++++++ .../sdk/Metrics/MetricFactoryInterface.php | 41 +++ .../sdk/Metrics/MetricMetadataInterface.php | 28 ++ .../sdk/Metrics/MetricReader/ExportingReader.php | 156 +++++++++ .../sdk/Metrics/MetricReaderInterface.php | 14 + .../MultiRegistryRegistration.php | 36 +++ .../MetricRegistration/RegistryRegistration.php | 31 ++ .../sdk/Metrics/MetricRegistrationInterface.php | 13 + .../MetricRegistry/MetricCollectorInterface.php | 13 + .../sdk/Metrics/MetricRegistry/MetricRegistry.php | 184 +++++++++++ .../MetricRegistry/MetricRegistryInterface.php | 22 ++ .../MetricRegistry/MetricWriterInterface.php | 20 ++ .../sdk/Metrics/MetricRegistry/MultiObserver.php | 37 +++ .../sdk/Metrics/MetricRegistry/NoopObserver.php | 18 ++ .../sdk/Metrics/MetricSourceInterface.php | 24 ++ .../sdk/Metrics/MetricSourceProviderInterface.php | 15 + .../sdk/Metrics/MetricSourceRegistryInterface.php | 10 + .../sdk/Metrics/NoopMeterProvider.php | 26 ++ .../sdk/Metrics/ObservableCallback.php | 58 ++++ .../sdk/Metrics/ObservableCallbackDestructor.php | 32 ++ .../sdk/Metrics/ObservableCounter.php | 15 + .../open-telemetry/sdk/Metrics/ObservableGauge.php | 15 + .../sdk/Metrics/ObservableInstrumentTrait.php | 61 ++++ .../sdk/Metrics/ObservableUpDownCounter.php | 15 + .../sdk/Metrics/PushMetricExporterInterface.php | 12 + .../sdk/Metrics/ReferenceCounterInterface.php | 15 + .../StalenessHandler/DelayedStalenessHandler.php | 71 ++++ .../DelayedStalenessHandlerFactory.php | 64 ++++ .../StalenessHandler/ImmediateStalenessHandler.php | 50 +++ .../ImmediateStalenessHandlerFactory.php | 16 + .../StalenessHandler/NoopStalenessHandler.php | 30 ++ .../NoopStalenessHandlerFactory.php | 18 ++ .../Metrics/StalenessHandlerFactoryInterface.php | 13 + .../sdk/Metrics/StalenessHandlerInterface.php | 12 + .../Metrics/Stream/AsynchronousMetricStream.php | 111 +++++++ vendor/open-telemetry/sdk/Metrics/Stream/Delta.php | 33 ++ .../sdk/Metrics/Stream/DeltaStorage.php | 110 +++++++ .../open-telemetry/sdk/Metrics/Stream/Metric.php | 44 +++ .../sdk/Metrics/Stream/MetricAggregator.php | 73 +++++ .../sdk/Metrics/Stream/MetricAggregatorFactory.php | 28 ++ .../Stream/MetricAggregatorFactoryInterface.php | 13 + .../Metrics/Stream/MetricAggregatorInterface.php | 12 + .../Metrics/Stream/MetricCollectorInterface.php | 13 + .../sdk/Metrics/Stream/MetricStreamInterface.php | 58 ++++ .../sdk/Metrics/Stream/SynchronousMetricStream.php | 126 ++++++++ .../Stream/WritableMetricStreamInterface.php | 19 ++ .../open-telemetry/sdk/Metrics/UpDownCounter.php | 37 +++ .../sdk/Metrics/View/CriteriaViewRegistry.php | 40 +++ .../Metrics/View/SelectionCriteria/AllCriteria.php | 33 ++ .../SelectionCriteria/InstrumentNameCriteria.php | 28 ++ .../SelectionCriteria/InstrumentTypeCriteria.php | 29 ++ .../InstrumentationScopeNameCriteria.php | 24 ++ .../InstrumentationScopeSchemaUrlCriteria.php | 24 ++ .../InstrumentationScopeVersionCriteria.php | 24 ++ .../Metrics/View/SelectionCriteriaInterface.php | 13 + .../sdk/Metrics/View/ViewTemplate.php | 77 +++++ .../open-telemetry/sdk/Metrics/ViewProjection.php | 47 +++ .../sdk/Metrics/ViewRegistryInterface.php | 15 + .../sdk/Propagation/PropagatorFactory.php | 55 ++++ .../open-telemetry/sdk/Propagation/_register.php | 16 + vendor/open-telemetry/sdk/README.md | 49 +++ vendor/open-telemetry/sdk/Registry.php | 208 ++++++++++++ .../sdk/Resource/Detectors/Composer.php | 30 ++ .../sdk/Resource/Detectors/Composite.php | 32 ++ .../sdk/Resource/Detectors/Constant.php | 23 ++ .../sdk/Resource/Detectors/Environment.php | 40 +++ .../open-telemetry/sdk/Resource/Detectors/Host.php | 27 ++ .../sdk/Resource/Detectors/OperatingSystem.php | 32 ++ .../sdk/Resource/Detectors/Process.php | 43 +++ .../sdk/Resource/Detectors/ProcessRuntime.php | 28 ++ .../open-telemetry/sdk/Resource/Detectors/Sdk.php | 53 +++ .../sdk/Resource/Detectors/SdkProvided.php | 25 ++ .../sdk/Resource/ResourceDetectorInterface.php | 10 + .../open-telemetry/sdk/Resource/ResourceInfo.php | 125 +++++++ .../sdk/Resource/ResourceInfoFactory.php | 95 ++++++ vendor/open-telemetry/sdk/Sdk.php | 70 ++++ vendor/open-telemetry/sdk/SdkAutoloader.php | 76 +++++ vendor/open-telemetry/sdk/SdkBuilder.php | 98 ++++++ .../sdk/Trace/Behavior/LoggerAwareTrait.php | 48 +++ .../Trace/Behavior/SpanExporterDecoratorTrait.php | 47 +++ .../sdk/Trace/Behavior/SpanExporterTrait.php | 47 +++ .../sdk/Trace/Behavior/UsesSpanConverterTrait.php | 41 +++ vendor/open-telemetry/sdk/Trace/Event.php | 47 +++ vendor/open-telemetry/sdk/Trace/EventInterface.php | 15 + .../open-telemetry/sdk/Trace/ExporterFactory.php | 32 ++ .../sdk/Trace/IdGeneratorInterface.php | 12 + vendor/open-telemetry/sdk/Trace/ImmutableSpan.php | 153 +++++++++ vendor/open-telemetry/sdk/Trace/Link.php | 30 ++ vendor/open-telemetry/sdk/Trace/LinkInterface.php | 14 + .../sdk/Trace/NoopTracerProvider.php | 21 ++ .../open-telemetry/sdk/Trace/RandomIdGenerator.php | 49 +++ .../sdk/Trace/ReadWriteSpanInterface.php | 11 + .../sdk/Trace/ReadableSpanInterface.php | 48 +++ .../sdk/Trace/Sampler/AlwaysOffSampler.php | 50 +++ .../sdk/Trace/Sampler/AlwaysOnSampler.php | 50 +++ .../sdk/Trace/Sampler/ParentBased.php | 100 ++++++ .../sdk/Trace/Sampler/TraceIdRatioBasedSampler.php | 70 ++++ vendor/open-telemetry/sdk/Trace/SamplerFactory.php | 48 +++ .../open-telemetry/sdk/Trace/SamplerInterface.php | 46 +++ vendor/open-telemetry/sdk/Trace/SamplingResult.php | 71 ++++ vendor/open-telemetry/sdk/Trace/Span.php | 359 +++++++++++++++++++++ vendor/open-telemetry/sdk/Trace/SpanBuilder.php | 191 +++++++++++ .../sdk/Trace/SpanConverterInterface.php | 10 + .../open-telemetry/sdk/Trace/SpanDataInterface.php | 46 +++ .../sdk/Trace/SpanExporter/AbstractDecorator.php | 12 + .../sdk/Trace/SpanExporter/ConsoleSpanExporter.php | 57 ++++ .../SpanExporter/ConsoleSpanExporterFactory.php | 18 ++ .../Trace/SpanExporter/FriendlySpanConverter.php | 173 ++++++++++ .../sdk/Trace/SpanExporter/InMemoryExporter.php | 40 +++ .../SpanExporter/InMemorySpanExporterFactory.php | 15 + .../sdk/Trace/SpanExporter/LoggerDecorator.php | 58 ++++ .../sdk/Trace/SpanExporter/LoggerExporter.php | 96 ++++++ .../sdk/Trace/SpanExporter/NullSpanConverter.php | 15 + .../SpanExporter/SpanExporterFactoryInterface.php | 12 + .../sdk/Trace/SpanExporter/_register.php | 7 + .../sdk/Trace/SpanExporterInterface.php | 29 ++ vendor/open-telemetry/sdk/Trace/SpanLimits.php | 67 ++++ .../open-telemetry/sdk/Trace/SpanLimitsBuilder.php | 148 +++++++++ .../sdk/Trace/SpanProcessor/BatchSpanProcessor.php | 290 +++++++++++++++++ .../SpanProcessor/BatchSpanProcessorBuilder.php | 41 +++ .../sdk/Trace/SpanProcessor/MultiSpanProcessor.php | 79 +++++ .../sdk/Trace/SpanProcessor/NoopSpanProcessor.php | 47 +++ .../Trace/SpanProcessor/SimpleSpanProcessor.php | 120 +++++++ .../sdk/Trace/SpanProcessorFactory.php | 48 +++ .../sdk/Trace/SpanProcessorInterface.php | 38 +++ vendor/open-telemetry/sdk/Trace/StatusData.php | 84 +++++ .../sdk/Trace/StatusDataInterface.php | 18 ++ vendor/open-telemetry/sdk/Trace/Tracer.php | 52 +++ vendor/open-telemetry/sdk/Trace/TracerProvider.php | 99 ++++++ .../sdk/Trace/TracerProviderBuilder.php | 45 +++ .../sdk/Trace/TracerProviderFactory.php | 60 ++++ .../sdk/Trace/TracerProviderInterface.php | 15 + .../open-telemetry/sdk/Trace/TracerSharedState.php | 100 ++++++ vendor/open-telemetry/sdk/_autoload.php | 5 + vendor/open-telemetry/sdk/composer.json | 59 ++++ 286 files changed, 14929 insertions(+) create mode 100644 vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/DependencyResolver.php create mode 100644 vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/HttpPlugClientResolver.php create mode 100644 vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/MessageFactoryResolver.php create mode 100644 vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/PsrClientResolver.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/AttributeValidator.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/AttributeValidatorInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/Attributes.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilder.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilderInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/AttributesFactory.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/AttributesFactoryInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/AttributesInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/FilteredAttributesBuilder.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/FilteredAttributesFactory.php create mode 100644 vendor/open-telemetry/sdk/Common/Attribute/LogRecordAttributeValidator.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Configuration.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Defaults.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/KnownValues.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Parser/BooleanParser.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Parser/ListParser.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Parser/MapParser.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Parser/RatioParser.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Resolver/CompositeResolver.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Resolver/EnvironmentResolver.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Resolver/PhpIniAccessor.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Resolver/PhpIniResolver.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Resolver/ResolverInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/ValueTypes.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/VariableTypes.php create mode 100644 vendor/open-telemetry/sdk/Common/Configuration/Variables.php create mode 100644 vendor/open-telemetry/sdk/Common/Dev/Compatibility/README.md create mode 100644 vendor/open-telemetry/sdk/Common/Dev/Compatibility/Util.php create mode 100644 vendor/open-telemetry/sdk/Common/Dev/Compatibility/_load.php create mode 100644 vendor/open-telemetry/sdk/Common/Exception/StackTraceFormatter.php create mode 100644 vendor/open-telemetry/sdk/Common/Export/Http/PsrTransport.php create mode 100644 vendor/open-telemetry/sdk/Common/Export/Http/PsrTransportFactory.php create mode 100644 vendor/open-telemetry/sdk/Common/Export/Http/PsrUtils.php create mode 100644 vendor/open-telemetry/sdk/Common/Export/Stream/StreamTransport.php create mode 100644 vendor/open-telemetry/sdk/Common/Export/Stream/StreamTransportFactory.php create mode 100644 vendor/open-telemetry/sdk/Common/Export/TransportFactoryInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Export/TransportInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Future/CancellationInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Future/CompletedFuture.php create mode 100644 vendor/open-telemetry/sdk/Common/Future/ErrorFuture.php create mode 100644 vendor/open-telemetry/sdk/Common/Future/FutureInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Future/NullCancellation.php create mode 100644 vendor/open-telemetry/sdk/Common/Http/DependencyResolverInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Http/HttpPlug/Client/ResolverInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Http/Psr/Client/ResolverInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Http/Psr/Message/FactoryResolverInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Http/Psr/Message/MessageFactory.php create mode 100644 vendor/open-telemetry/sdk/Common/Http/Psr/Message/MessageFactoryInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScope.php create mode 100644 vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScopeFactory.php create mode 100644 vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScopeFactoryInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScopeInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Time/ClockFactory.php create mode 100644 vendor/open-telemetry/sdk/Common/Time/ClockFactoryInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Time/ClockInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Time/StopWatch.php create mode 100644 vendor/open-telemetry/sdk/Common/Time/StopWatchFactory.php create mode 100644 vendor/open-telemetry/sdk/Common/Time/StopWatchFactoryInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Time/StopWatchInterface.php create mode 100644 vendor/open-telemetry/sdk/Common/Time/SystemClock.php create mode 100644 vendor/open-telemetry/sdk/Common/Time/Util.php create mode 100644 vendor/open-telemetry/sdk/Common/Util/ClassConstantAccessor.php create mode 100644 vendor/open-telemetry/sdk/Common/Util/ShutdownHandler.php create mode 100644 vendor/open-telemetry/sdk/Common/Util/WeakMap.php create mode 100644 vendor/open-telemetry/sdk/Common/Util/functions.php create mode 100644 vendor/open-telemetry/sdk/Logs/Exporter/ConsoleExporter.php create mode 100644 vendor/open-telemetry/sdk/Logs/Exporter/ConsoleExporterFactory.php create mode 100644 vendor/open-telemetry/sdk/Logs/Exporter/InMemoryExporter.php create mode 100644 vendor/open-telemetry/sdk/Logs/Exporter/InMemoryExporterFactory.php create mode 100644 vendor/open-telemetry/sdk/Logs/Exporter/NoopExporter.php create mode 100644 vendor/open-telemetry/sdk/Logs/Exporter/_register.php create mode 100644 vendor/open-telemetry/sdk/Logs/ExporterFactory.php create mode 100644 vendor/open-telemetry/sdk/Logs/LogRecordExporterFactoryInterface.php create mode 100644 vendor/open-telemetry/sdk/Logs/LogRecordExporterInterface.php create mode 100644 vendor/open-telemetry/sdk/Logs/LogRecordLimits.php create mode 100644 vendor/open-telemetry/sdk/Logs/LogRecordLimitsBuilder.php create mode 100644 vendor/open-telemetry/sdk/Logs/LogRecordProcessorFactory.php create mode 100644 vendor/open-telemetry/sdk/Logs/LogRecordProcessorInterface.php create mode 100644 vendor/open-telemetry/sdk/Logs/Logger.php create mode 100644 vendor/open-telemetry/sdk/Logs/LoggerProvider.php create mode 100644 vendor/open-telemetry/sdk/Logs/LoggerProviderBuilder.php create mode 100644 vendor/open-telemetry/sdk/Logs/LoggerProviderFactory.php create mode 100644 vendor/open-telemetry/sdk/Logs/LoggerProviderInterface.php create mode 100644 vendor/open-telemetry/sdk/Logs/LoggerSharedState.php create mode 100644 vendor/open-telemetry/sdk/Logs/NoopLoggerProvider.php create mode 100644 vendor/open-telemetry/sdk/Logs/Processor/BatchLogRecordProcessor.php create mode 100644 vendor/open-telemetry/sdk/Logs/Processor/MultiLogRecordProcessor.php create mode 100644 vendor/open-telemetry/sdk/Logs/Processor/NoopLogRecordProcessor.php create mode 100644 vendor/open-telemetry/sdk/Logs/Processor/SimpleLogRecordProcessor.php create mode 100644 vendor/open-telemetry/sdk/Logs/PsrSeverityMapperInterface.php create mode 100644 vendor/open-telemetry/sdk/Logs/ReadWriteLogRecord.php create mode 100644 vendor/open-telemetry/sdk/Logs/ReadableLogRecord.php create mode 100644 vendor/open-telemetry/sdk/Logs/SimplePsrFileLogger.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Aggregation/ExplicitBucketHistogramAggregation.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Aggregation/ExplicitBucketHistogramSummary.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Aggregation/LastValueAggregation.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Aggregation/LastValueSummary.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Aggregation/SumAggregation.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Aggregation/SumSummary.php create mode 100644 vendor/open-telemetry/sdk/Metrics/AggregationInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/AggregationTemporalitySelectorInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/AttributeProcessor/FilteredAttributeProcessor.php create mode 100644 vendor/open-telemetry/sdk/Metrics/AttributeProcessor/IdentityAttributeProcessor.php create mode 100644 vendor/open-telemetry/sdk/Metrics/AttributeProcessorInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Counter.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Data/DataInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Data/Exemplar.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Data/Gauge.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Data/Histogram.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Data/HistogramDataPoint.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Data/Metric.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Data/NumberDataPoint.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Data/Sum.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Data/Temporality.php create mode 100644 vendor/open-telemetry/sdk/Metrics/DefaultAggregationProviderInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/DefaultAggregationProviderTrait.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Exemplar/BucketEntry.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Exemplar/BucketStorage.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Exemplar/ExemplarFilter/AllExemplarFilter.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Exemplar/ExemplarFilter/NoneExemplarFilter.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Exemplar/ExemplarFilter/WithSampledTraceExemplarFilter.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Exemplar/ExemplarFilterInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Exemplar/ExemplarReservoirInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Exemplar/FilteredReservoir.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Exemplar/FixedSizeReservoir.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Exemplar/HistogramBucketReservoir.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Exemplar/NoopReservoir.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Histogram.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Instrument.php create mode 100644 vendor/open-telemetry/sdk/Metrics/InstrumentType.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Meter.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MeterInstruments.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MeterProvider.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MeterProviderBuilder.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MeterProviderFactory.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MeterProviderInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricExporter/ConsoleMetricExporter.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricExporter/ConsoleMetricExporterFactory.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricExporter/InMemoryExporter.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricExporter/InMemoryExporterFactory.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricExporter/NoopMetricExporter.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricExporter/NoopMetricExporterFactory.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricExporter/_register.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricExporterFactoryInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricExporterInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamFactory.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamMetricSource.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamMetricSourceProvider.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricFactoryInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricMetadataInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricReader/ExportingReader.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricReaderInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricRegistration/MultiRegistryRegistration.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricRegistration/RegistryRegistration.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricRegistrationInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricRegistry/MetricCollectorInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricRegistry/MetricRegistry.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricRegistry/MetricRegistryInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricRegistry/MetricWriterInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricRegistry/MultiObserver.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricRegistry/NoopObserver.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricSourceInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricSourceProviderInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/MetricSourceRegistryInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/NoopMeterProvider.php create mode 100644 vendor/open-telemetry/sdk/Metrics/ObservableCallback.php create mode 100644 vendor/open-telemetry/sdk/Metrics/ObservableCallbackDestructor.php create mode 100644 vendor/open-telemetry/sdk/Metrics/ObservableCounter.php create mode 100644 vendor/open-telemetry/sdk/Metrics/ObservableGauge.php create mode 100644 vendor/open-telemetry/sdk/Metrics/ObservableInstrumentTrait.php create mode 100644 vendor/open-telemetry/sdk/Metrics/ObservableUpDownCounter.php create mode 100644 vendor/open-telemetry/sdk/Metrics/PushMetricExporterInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/ReferenceCounterInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/StalenessHandler/DelayedStalenessHandler.php create mode 100644 vendor/open-telemetry/sdk/Metrics/StalenessHandler/DelayedStalenessHandlerFactory.php create mode 100644 vendor/open-telemetry/sdk/Metrics/StalenessHandler/ImmediateStalenessHandler.php create mode 100644 vendor/open-telemetry/sdk/Metrics/StalenessHandler/ImmediateStalenessHandlerFactory.php create mode 100644 vendor/open-telemetry/sdk/Metrics/StalenessHandler/NoopStalenessHandler.php create mode 100644 vendor/open-telemetry/sdk/Metrics/StalenessHandler/NoopStalenessHandlerFactory.php create mode 100644 vendor/open-telemetry/sdk/Metrics/StalenessHandlerFactoryInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/StalenessHandlerInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Stream/AsynchronousMetricStream.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Stream/Delta.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Stream/DeltaStorage.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Stream/Metric.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Stream/MetricAggregator.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Stream/MetricAggregatorFactory.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Stream/MetricAggregatorFactoryInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Stream/MetricAggregatorInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Stream/MetricCollectorInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Stream/MetricStreamInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Stream/SynchronousMetricStream.php create mode 100644 vendor/open-telemetry/sdk/Metrics/Stream/WritableMetricStreamInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/UpDownCounter.php create mode 100644 vendor/open-telemetry/sdk/Metrics/View/CriteriaViewRegistry.php create mode 100644 vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/AllCriteria.php create mode 100644 vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentNameCriteria.php create mode 100644 vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentTypeCriteria.php create mode 100644 vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeNameCriteria.php create mode 100644 vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeSchemaUrlCriteria.php create mode 100644 vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeVersionCriteria.php create mode 100644 vendor/open-telemetry/sdk/Metrics/View/SelectionCriteriaInterface.php create mode 100644 vendor/open-telemetry/sdk/Metrics/View/ViewTemplate.php create mode 100644 vendor/open-telemetry/sdk/Metrics/ViewProjection.php create mode 100644 vendor/open-telemetry/sdk/Metrics/ViewRegistryInterface.php create mode 100644 vendor/open-telemetry/sdk/Propagation/PropagatorFactory.php create mode 100644 vendor/open-telemetry/sdk/Propagation/_register.php create mode 100644 vendor/open-telemetry/sdk/README.md create mode 100644 vendor/open-telemetry/sdk/Registry.php create mode 100644 vendor/open-telemetry/sdk/Resource/Detectors/Composer.php create mode 100644 vendor/open-telemetry/sdk/Resource/Detectors/Composite.php create mode 100644 vendor/open-telemetry/sdk/Resource/Detectors/Constant.php create mode 100644 vendor/open-telemetry/sdk/Resource/Detectors/Environment.php create mode 100644 vendor/open-telemetry/sdk/Resource/Detectors/Host.php create mode 100644 vendor/open-telemetry/sdk/Resource/Detectors/OperatingSystem.php create mode 100644 vendor/open-telemetry/sdk/Resource/Detectors/Process.php create mode 100644 vendor/open-telemetry/sdk/Resource/Detectors/ProcessRuntime.php create mode 100644 vendor/open-telemetry/sdk/Resource/Detectors/Sdk.php create mode 100644 vendor/open-telemetry/sdk/Resource/Detectors/SdkProvided.php create mode 100644 vendor/open-telemetry/sdk/Resource/ResourceDetectorInterface.php create mode 100644 vendor/open-telemetry/sdk/Resource/ResourceInfo.php create mode 100644 vendor/open-telemetry/sdk/Resource/ResourceInfoFactory.php create mode 100644 vendor/open-telemetry/sdk/Sdk.php create mode 100644 vendor/open-telemetry/sdk/SdkAutoloader.php create mode 100644 vendor/open-telemetry/sdk/SdkBuilder.php create mode 100644 vendor/open-telemetry/sdk/Trace/Behavior/LoggerAwareTrait.php create mode 100644 vendor/open-telemetry/sdk/Trace/Behavior/SpanExporterDecoratorTrait.php create mode 100644 vendor/open-telemetry/sdk/Trace/Behavior/SpanExporterTrait.php create mode 100644 vendor/open-telemetry/sdk/Trace/Behavior/UsesSpanConverterTrait.php create mode 100644 vendor/open-telemetry/sdk/Trace/Event.php create mode 100644 vendor/open-telemetry/sdk/Trace/EventInterface.php create mode 100644 vendor/open-telemetry/sdk/Trace/ExporterFactory.php create mode 100644 vendor/open-telemetry/sdk/Trace/IdGeneratorInterface.php create mode 100644 vendor/open-telemetry/sdk/Trace/ImmutableSpan.php create mode 100644 vendor/open-telemetry/sdk/Trace/Link.php create mode 100644 vendor/open-telemetry/sdk/Trace/LinkInterface.php create mode 100644 vendor/open-telemetry/sdk/Trace/NoopTracerProvider.php create mode 100644 vendor/open-telemetry/sdk/Trace/RandomIdGenerator.php create mode 100644 vendor/open-telemetry/sdk/Trace/ReadWriteSpanInterface.php create mode 100644 vendor/open-telemetry/sdk/Trace/ReadableSpanInterface.php create mode 100644 vendor/open-telemetry/sdk/Trace/Sampler/AlwaysOffSampler.php create mode 100644 vendor/open-telemetry/sdk/Trace/Sampler/AlwaysOnSampler.php create mode 100644 vendor/open-telemetry/sdk/Trace/Sampler/ParentBased.php create mode 100644 vendor/open-telemetry/sdk/Trace/Sampler/TraceIdRatioBasedSampler.php create mode 100644 vendor/open-telemetry/sdk/Trace/SamplerFactory.php create mode 100644 vendor/open-telemetry/sdk/Trace/SamplerInterface.php create mode 100644 vendor/open-telemetry/sdk/Trace/SamplingResult.php create mode 100644 vendor/open-telemetry/sdk/Trace/Span.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanBuilder.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanConverterInterface.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanDataInterface.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanExporter/AbstractDecorator.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanExporter/ConsoleSpanExporter.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanExporter/ConsoleSpanExporterFactory.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanExporter/FriendlySpanConverter.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanExporter/InMemoryExporter.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanExporter/InMemorySpanExporterFactory.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanExporter/LoggerDecorator.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanExporter/LoggerExporter.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanExporter/NullSpanConverter.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanExporter/SpanExporterFactoryInterface.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanExporter/_register.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanExporterInterface.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanLimits.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanLimitsBuilder.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanProcessor/BatchSpanProcessor.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanProcessor/BatchSpanProcessorBuilder.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanProcessor/MultiSpanProcessor.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanProcessor/NoopSpanProcessor.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanProcessor/SimpleSpanProcessor.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanProcessorFactory.php create mode 100644 vendor/open-telemetry/sdk/Trace/SpanProcessorInterface.php create mode 100644 vendor/open-telemetry/sdk/Trace/StatusData.php create mode 100644 vendor/open-telemetry/sdk/Trace/StatusDataInterface.php create mode 100644 vendor/open-telemetry/sdk/Trace/Tracer.php create mode 100644 vendor/open-telemetry/sdk/Trace/TracerProvider.php create mode 100644 vendor/open-telemetry/sdk/Trace/TracerProviderBuilder.php create mode 100644 vendor/open-telemetry/sdk/Trace/TracerProviderFactory.php create mode 100644 vendor/open-telemetry/sdk/Trace/TracerProviderInterface.php create mode 100644 vendor/open-telemetry/sdk/Trace/TracerSharedState.php create mode 100644 vendor/open-telemetry/sdk/_autoload.php create mode 100644 vendor/open-telemetry/sdk/composer.json (limited to 'vendor/open-telemetry/sdk') diff --git a/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/DependencyResolver.php b/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/DependencyResolver.php new file mode 100644 index 000000000..8ba992f9a --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/DependencyResolver.php @@ -0,0 +1,83 @@ +messageFactoryResolver = $messageFactoryResolver ?? MessageFactoryResolver::create(); + $this->psrClientResolver = $psrClientResolver ?? PsrClientResolver::create(); + $this->httpPlugClientResolver = $httpPlugClientResolver ?? HttpPlugClientResolver::create(); + } + + public static function create( + ?MessageFactoryResolverInterface $messageFactoryResolver = null, + ?PsrClientResolverInterface $psrClientResolver = null, + ?HttpPlugClientResolverInterface $httpPlugClientResolver = null + ): self { + return new self($messageFactoryResolver, $psrClientResolver, $httpPlugClientResolver); + } + + public function resolveRequestFactory(): RequestFactoryInterface + { + return $this->messageFactoryResolver->resolveRequestFactory(); + } + + public function resolveResponseFactory(): ResponseFactoryInterface + { + return $this->messageFactoryResolver->resolveResponseFactory(); + } + + public function resolveServerRequestFactory(): ServerRequestFactoryInterface + { + return $this->messageFactoryResolver->resolveServerRequestFactory(); + } + + public function resolveStreamFactory(): StreamFactoryInterface + { + return $this->messageFactoryResolver->resolveStreamFactory(); + } + + public function resolveUploadedFileFactory(): UploadedFileFactoryInterface + { + return $this->messageFactoryResolver->resolveUploadedFileFactory(); + } + + public function resolveUriFactory(): UriFactoryInterface + { + return $this->messageFactoryResolver->resolveUriFactory(); + } + + public function resolveHttpPlugAsyncClient(): HttpAsyncClient + { + return $this->httpPlugClientResolver->resolveHttpPlugAsyncClient(); + } + + public function resolvePsrClient(): ClientInterface + { + return $this->psrClientResolver->resolvePsrClient(); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/HttpPlugClientResolver.php b/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/HttpPlugClientResolver.php new file mode 100644 index 000000000..9751984ee --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/HttpPlugClientResolver.php @@ -0,0 +1,29 @@ +httpAsyncClient = $httpAsyncClient; + } + + public static function create(?HttpAsyncClient $httpAsyncClient = null): self + { + return new self($httpAsyncClient); + } + + public function resolveHttpPlugAsyncClient(): HttpAsyncClient + { + return $this->httpAsyncClient ??= HttpAsyncClientDiscovery::find(); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/MessageFactoryResolver.php b/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/MessageFactoryResolver.php new file mode 100644 index 000000000..6ed0895ff --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/MessageFactoryResolver.php @@ -0,0 +1,88 @@ +requestFactory = $requestFactory; + $this->responseFactory = $responseFactory; + $this->serverRequestFactory = $serverRequestFactory; + $this->streamFactory = $streamFactory; + $this->uploadedFileFactory = $uploadedFileFactory; + $this->uriFactory = $uriFactory; + } + + public static function create( + ?RequestFactoryInterface $requestFactory = null, + ?ResponseFactoryInterface $responseFactory = null, + ?ServerRequestFactoryInterface $serverRequestFactory = null, + ?StreamFactoryInterface $streamFactory = null, + ?UploadedFileFactoryInterface $uploadedFileFactory = null, + ?UriFactoryInterface $uriFactory = null + ): self { + return new self( + $requestFactory, + $responseFactory, + $serverRequestFactory, + $streamFactory, + $uploadedFileFactory, + $uriFactory + ); + } + + public function resolveRequestFactory(): RequestFactoryInterface + { + return $this->requestFactory ??= Psr17FactoryDiscovery::findRequestFactory(); + } + + public function resolveResponseFactory(): ResponseFactoryInterface + { + return $this->responseFactory ??= Psr17FactoryDiscovery::findResponseFactory(); + } + + public function resolveServerRequestFactory(): ServerRequestFactoryInterface + { + return $this->serverRequestFactory ??= Psr17FactoryDiscovery::findServerRequestFactory(); + } + + public function resolveStreamFactory(): StreamFactoryInterface + { + return $this->streamFactory ??= Psr17FactoryDiscovery::findStreamFactory(); + } + + public function resolveUploadedFileFactory(): UploadedFileFactoryInterface + { + return $this->uploadedFileFactory ??= Psr17FactoryDiscovery::findUploadedFileFactory(); + } + + public function resolveUriFactory(): UriFactoryInterface + { + return $this->uriFactory ??= Psr17FactoryDiscovery::findUriFactory(); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/PsrClientResolver.php b/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/PsrClientResolver.php new file mode 100644 index 000000000..46fb36312 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Adapter/HttpDiscovery/PsrClientResolver.php @@ -0,0 +1,29 @@ +client = $client; + } + + public static function create(?ClientInterface $client = null): self + { + return new self($client); + } + + public function resolvePsrClient(): ClientInterface + { + return $this->client ??= Psr18ClientDiscovery::find(); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Attribute/AttributeValidator.php b/vendor/open-telemetry/sdk/Common/Attribute/AttributeValidator.php new file mode 100644 index 000000000..e9a1f7334 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Attribute/AttributeValidator.php @@ -0,0 +1,58 @@ +validateArray($value); + } + + return in_array(gettype($value), self::PRIMITIVES); + } + + private function validateArray(array $value): bool + { + if ($value === []) { + return true; + } + $type = gettype(reset($value)); + if (!in_array($type, self::PRIMITIVES)) { + return false; + } + foreach ($value as $v) { + if (in_array(gettype($v), self::NUMERICS) && in_array($type, self::NUMERICS)) { + continue; + } + if (gettype($v) !== $type) { + return false; + } + } + + return true; + } + + public function getInvalidMessage(): string + { + return 'attribute with non-primitive or non-homogeneous array of primitives dropped'; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Attribute/AttributeValidatorInterface.php b/vendor/open-telemetry/sdk/Common/Attribute/AttributeValidatorInterface.php new file mode 100644 index 000000000..afbfba6e7 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Attribute/AttributeValidatorInterface.php @@ -0,0 +1,11 @@ +attributes = $attributes; + $this->droppedAttributesCount = $droppedAttributesCount; + } + + public static function create(iterable $attributes): AttributesInterface + { + return self::factory()->builder($attributes)->build(); + } + + public static function factory(?int $attributeCountLimit = null, ?int $attributeValueLengthLimit = null): AttributesFactoryInterface + { + return new AttributesFactory($attributeCountLimit, $attributeValueLengthLimit); + } + + public function has(string $name): bool + { + return array_key_exists($name, $this->attributes); + } + + public function get(string $name) + { + return $this->attributes[$name] ?? null; + } + + /** @psalm-mutation-free */ + public function count(): int + { + return \count($this->attributes); + } + + public function getIterator(): Traversable + { + foreach ($this->attributes as $key => $value) { + yield (string) $key => $value; + } + } + + public function toArray(): array + { + return $this->attributes; + } + + public function getDroppedAttributesCount(): int + { + return $this->droppedAttributesCount; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilder.php b/vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilder.php new file mode 100644 index 000000000..5c1150638 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilder.php @@ -0,0 +1,120 @@ +attributes = $attributes; + $this->attributeCountLimit = $attributeCountLimit; + $this->attributeValueLengthLimit = $attributeValueLengthLimit; + $this->droppedAttributesCount = $droppedAttributesCount; + $this->attributeValidator = $attributeValidator ?? new AttributeValidator(); + } + + public function build(): AttributesInterface + { + return new Attributes($this->attributes, $this->droppedAttributesCount); + } + + public function offsetExists($offset): bool + { + return array_key_exists($offset, $this->attributes); + } + + /** + * @phan-suppress PhanUndeclaredClassAttribute + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + return $this->attributes[$offset] ?? null; + } + + /** + * @phan-suppress PhanUndeclaredClassAttribute + */ + #[\ReturnTypeWillChange] + public function offsetSet($offset, $value) + { + if ($offset === null) { + return; + } + if ($value === null) { + unset($this->attributes[$offset]); + + return; + } + if (!$this->attributeValidator->validate($value)) { + self::logWarning($this->attributeValidator->getInvalidMessage() . ': ' . $offset); + $this->droppedAttributesCount++; + + return; + } + if (count($this->attributes) === $this->attributeCountLimit && !array_key_exists($offset, $this->attributes)) { + $this->droppedAttributesCount++; + + return; + } + + $this->attributes[$offset] = $this->normalizeValue($value); + //@todo "There SHOULD be a message printed in the SDK's log to indicate to the user that an attribute was + // discarded due to such a limit. To prevent excessive logging, the message MUST be printed at most + // once per (i.e., not per discarded attribute)." + } + + /** + * @phan-suppress PhanUndeclaredClassAttribute + */ + #[\ReturnTypeWillChange] + public function offsetUnset($offset) + { + unset($this->attributes[$offset]); + } + + private function normalizeValue($value) + { + if (is_string($value) && $this->attributeValueLengthLimit !== null) { + return mb_substr($value, 0, $this->attributeValueLengthLimit); + } + + if (is_array($value)) { + foreach ($value as $k => $v) { + $processed = $this->normalizeValue($v); + if ($processed !== $v) { + $value[$k] = $processed; + } + } + + return $value; + } + + return $value; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilderInterface.php b/vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilderInterface.php new file mode 100644 index 000000000..7e3d64062 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Attribute/AttributesBuilderInterface.php @@ -0,0 +1,12 @@ +attributeCountLimit = $attributeCountLimit; + $this->attributeValueLengthLimit = $attributeValueLengthLimit; + } + + public function builder(iterable $attributes = [], ?AttributeValidatorInterface $attributeValidator = null): AttributesBuilderInterface + { + $builder = new AttributesBuilder( + [], + $this->attributeCountLimit, + $this->attributeValueLengthLimit, + 0, + $attributeValidator, + ); + foreach ($attributes as $key => $value) { + $builder[$key] = $value; + } + + return $builder; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Attribute/AttributesFactoryInterface.php b/vendor/open-telemetry/sdk/Common/Attribute/AttributesFactoryInterface.php new file mode 100644 index 000000000..1b74461d4 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Attribute/AttributesFactoryInterface.php @@ -0,0 +1,10 @@ + $rejectedKeys + */ + public function __construct(AttributesBuilderInterface $builder, array $rejectedKeys) + { + $this->builder = $builder; + $this->rejectedKeys = $rejectedKeys; + } + + public function __clone() + { + $this->builder = clone $this->builder; + } + + public function build(): AttributesInterface + { + $attributes = $this->builder->build(); + $dropped = $attributes->getDroppedAttributesCount() + $this->rejected; + + return new Attributes($attributes->toArray(), $dropped); + } + + public function offsetExists($offset): bool + { + return $this->builder->offsetExists($offset); + } + + /** + * @phan-suppress PhanUndeclaredClassAttribute + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + return $this->builder->offsetGet($offset); + } + + /** + * @phan-suppress PhanUndeclaredClassAttribute + */ + #[\ReturnTypeWillChange] + public function offsetSet($offset, $value) + { + if ($value !== null && in_array($offset, $this->rejectedKeys, true)) { + $this->rejected++; + + return; + } + + $this->builder->offsetSet($offset, $value); + } + + /** + * @phan-suppress PhanUndeclaredClassAttribute + */ + #[\ReturnTypeWillChange] + public function offsetUnset($offset) + { + $this->builder->offsetUnset($offset); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Attribute/FilteredAttributesFactory.php b/vendor/open-telemetry/sdk/Common/Attribute/FilteredAttributesFactory.php new file mode 100644 index 000000000..1d9c4ae1c --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Attribute/FilteredAttributesFactory.php @@ -0,0 +1,33 @@ + $rejectedKeys + */ + public function __construct(AttributesFactoryInterface $factory, array $rejectedKeys) + { + $this->factory = $factory; + $this->rejectedKeys = $rejectedKeys; + } + + public function builder(iterable $attributes = [], ?AttributeValidatorInterface $attributeValidator = null): AttributesBuilderInterface + { + $builder = new FilteredAttributesBuilder($this->factory->builder([], $attributeValidator), $this->rejectedKeys); + foreach ($attributes as $attribute => $value) { + $builder[$attribute] = $value; + } + + return $builder; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Attribute/LogRecordAttributeValidator.php b/vendor/open-telemetry/sdk/Common/Attribute/LogRecordAttributeValidator.php new file mode 100644 index 000000000..a09d26372 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Attribute/LogRecordAttributeValidator.php @@ -0,0 +1,19 @@ +hasVariable($name); + } + + public static function getInt(string $key, int $default = null): int + { + return (int) self::validateVariableValue( + CompositeResolver::instance()->resolve( + self::validateVariableType($key, VariableTypes::INTEGER), + $default + ), + FILTER_VALIDATE_INT + ); + } + + public static function getString(string $key, string $default = null): string + { + return (string) self::validateVariableValue( + CompositeResolver::instance()->resolve( + self::validateVariableType($key, VariableTypes::STRING), + $default + ) + ); + } + + public static function getBoolean(string $key, bool $default = null): bool + { + $resolved = self::validateVariableValue( + CompositeResolver::instance()->resolve( + self::validateVariableType($key, VariableTypes::BOOL), + null === $default ? $default : ($default ? 'true' : 'false') + ) + ); + + try { + return BooleanParser::parse($resolved); + } catch (InvalidArgumentException $e) { + self::logWarning(sprintf('Invalid boolean value "%s" interpreted as "false" for %s', $resolved, $key)); + + return false; + } + } + + public static function getMixed(string $key, $default = null) + { + return self::validateVariableValue( + CompositeResolver::instance()->resolve( + $key, + $default + ) + ); + } + + public static function getMap(string $key, array $default = null): array + { + return MapParser::parse( + CompositeResolver::instance()->resolve( + self::validateVariableType($key, VariableTypes::MAP), + $default + ) + ); + } + + public static function getList(string $key, array $default = null): array + { + return ListParser::parse( + CompositeResolver::instance()->resolve( + self::validateVariableType($key, VariableTypes::LIST), + $default + ) + ); + } + + public static function getEnum(string $key, string $default = null): string + { + return (string) self::validateVariableValue( + CompositeResolver::instance()->resolve( + self::validateVariableType($key, VariableTypes::ENUM), + $default + ) + ); + } + + public static function getFloat(string $key, float $default = null): float + { + return (float) self::validateVariableValue( + CompositeResolver::instance()->resolve( + self::validateVariableType($key, VariableTypes::FLOAT), + $default + ), + FILTER_VALIDATE_FLOAT + ); + } + + public static function getRatio(string $key, float $default = null): float + { + return RatioParser::parse( + self::validateVariableValue( + CompositeResolver::instance()->resolve( + self::validateVariableType($key, VariableTypes::RATIO), + $default + ) + ) + ); + } + + public static function getKnownValues(string $variableName): ?array + { + return ClassConstantAccessor::getValue(KnownValues::class, $variableName); + } + + public static function getDefault(string $variableName) + { + return ClassConstantAccessor::getValue(Defaults::class, $variableName); + } + + public static function getType(string $variableName): ?string + { + return ClassConstantAccessor::getValue(ValueTypes::class, $variableName); + } + + public static function isEmpty($value): bool + { + // don't use 'empty()', since '0' is not considered to be empty + return $value === null || $value === ''; + } + + private static function validateVariableType(string $variableName, string $type): string + { + $variableType = self::getType($variableName); + + if ($variableType !== null && $variableType !== $type && $variableType !== VariableTypes::MIXED) { + throw new UnexpectedValueException( + sprintf('Variable "%s" is not supposed to be of type "%s" but type "%s"', $variableName, $type, $variableType) + ); + } + + return $variableName; + } + + private static function validateVariableValue($value, ?int $filterType = null) + { + if ($filterType !== null && filter_var($value, $filterType) === false) { + throw new UnexpectedValueException(sprintf('Value has invalid type "%s"', gettype($value))); + } + + if ($value === null || $value === '') { + throw new UnexpectedValueException( + 'Variable must not be null or empty' + ); + } + + return $value; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Configuration/Defaults.php b/vendor/open-telemetry/sdk/Common/Configuration/Defaults.php new file mode 100644 index 000000000..7228270a6 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Configuration/Defaults.php @@ -0,0 +1,122 @@ + trim($value), + explode(self::DEFAULT_SEPARATOR, $value) + ); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Configuration/Parser/MapParser.php b/vendor/open-telemetry/sdk/Common/Configuration/Parser/MapParser.php new file mode 100644 index 000000000..273d57c87 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Configuration/Parser/MapParser.php @@ -0,0 +1,45 @@ + self::MAX_VALUE || $result < self::MIN_VALUE) { + throw new RangeException( + sprintf( + 'Value must not be lower than %s or higher than %s. Given: %s', + self::MIN_VALUE, + self::MAX_VALUE, + $value + ) + ); + } + + return $result; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Configuration/Resolver/CompositeResolver.php b/vendor/open-telemetry/sdk/Common/Configuration/Resolver/CompositeResolver.php new file mode 100644 index 000000000..b72400b01 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Configuration/Resolver/CompositeResolver.php @@ -0,0 +1,68 @@ + + private array $resolvers = []; + + public static function instance(): self + { + static $instance; + $instance ??= new self([ + new PhpIniResolver(), + new EnvironmentResolver(), + ]); + + return $instance; + } + + public function __construct($resolvers) + { + foreach ($resolvers as $resolver) { + $this->addResolver($resolver); + } + } + + public function addResolver(ResolverInterface $resolver): void + { + $this->resolvers[] = $resolver; + } + + public function getResolvers(): array + { + return $this->resolvers; + } + + public function resolve(string $variableName, $default = '') + { + foreach ($this->resolvers as $resolver) { + if ($resolver->hasVariable($variableName)) { + return $resolver->retrieveValue($variableName); + } + } + + return Configuration::isEmpty($default) + ? Configuration::getDefault($variableName) + : $default; + } + + public function hasVariable(string $variableName): bool + { + foreach ($this->resolvers as $resolver) { + if ($resolver->hasVariable($variableName)) { + return true; + } + } + + return false; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Configuration/Resolver/EnvironmentResolver.php b/vendor/open-telemetry/sdk/Common/Configuration/Resolver/EnvironmentResolver.php new file mode 100644 index 000000000..453f98e39 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Configuration/Resolver/EnvironmentResolver.php @@ -0,0 +1,40 @@ +accessor = $accessor ?? new PhpIniAccessor(); + } + + public function retrieveValue(string $variableName) + { + $value = $this->accessor->get($variableName) ?: ''; + if (is_array($value)) { + return implode(',', $value); + } + + return $value; + } + + public function hasVariable(string $variableName): bool + { + $value = $this->accessor->get($variableName); + if ($value === []) { + return false; + } + + return $value !== false && !Configuration::isEmpty($value); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Configuration/Resolver/ResolverInterface.php b/vendor/open-telemetry/sdk/Common/Configuration/Resolver/ResolverInterface.php new file mode 100644 index 000000000..4e88f3ff6 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Configuration/Resolver/ResolverInterface.php @@ -0,0 +1,15 @@ + + */ +final class StackTraceFormatter +{ + private function __construct() + { + } + + /** + * Formats an exception in a java-like format. + * + * @param Throwable $e exception to format + * @return string formatted exception + * + * @see https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Throwable.html#printStackTrace() + */ + public static function format(Throwable $e): string + { + $s = ''; + $seen = []; + + /** @var Frames|null $enclosing */ + $enclosing = null; + do { + if ($enclosing) { + self::writeNewline($s); + $s .= 'Caused by: '; + } + if (isset($seen[spl_object_id($e)])) { + $s .= '[CIRCULAR REFERENCE: '; + self::writeInlineHeader($s, $e); + $s .= ']'; + + break; + } + $seen[spl_object_id($e)] = $e; + + $frames = self::frames($e); + self::writeInlineHeader($s, $e); + self::writeFrames($s, $frames, $enclosing); + + $enclosing = $frames; + } while ($e = $e->getPrevious()); + + return $s; + } + + /** + * @phan-suppress-next-line PhanTypeMismatchDeclaredParam + * @param Frames $frames + * @phan-suppress-next-line PhanTypeMismatchDeclaredParam + * @param Frames|null $enclosing + */ + private static function writeFrames(string &$s, array $frames, ?array $enclosing): void + { + $n = count($frames); + if ($enclosing) { + for ($m = count($enclosing); + $n && $m && $frames[$n - 1] === $enclosing[$m - 1]; + $n--, $m--) { + } + } + for ($i = 0; $i < $n; $i++) { + $frame = $frames[$i]; + self::writeNewline($s, 1); + $s .= 'at '; + if ($frame['class'] !== null) { + $s .= self::formatName($frame['class']); + $s .= '.'; + } + $s .= self::formatName($frame['function']); + $s .= '('; + if ($frame['file'] !== null) { + $s .= basename($frame['file']); + if ($frame['line']) { + $s .= ':'; + $s .= $frame['line']; + } + } else { + $s .= 'Unknown Source'; + } + $s .= ')'; + } + if ($n !== count($frames)) { + self::writeNewline($s, 1); + $s .= sprintf('... %d more', count($frames) - $n); + } + } + + private static function writeInlineHeader(string &$s, Throwable $e): void + { + $s .= self::formatName(get_class($e)); + if ($e->getMessage() !== '') { + $s .= ': '; + $s .= $e->getMessage(); + } + } + + private static function writeNewline(string &$s, int $indent = 0): void + { + $s .= "\n"; + $s .= str_repeat("\t", $indent); + } + + /** + * @return Frames + * + * @psalm-suppress PossiblyUndefinedArrayOffset + */ + private static function frames(Throwable $e): array + { + $frames = []; + $trace = $e->getTrace(); + $traceCount = count($trace); + for ($i = 0; $i < $traceCount + 1; $i++) { + $frames[] = [ + 'function' => $trace[$i]['function'] ?? '{main}', + 'class' => $trace[$i]['class'] ?? null, + 'file' => $trace[$i - 1]['file'] ?? null, + 'line' => $trace[$i - 1]['line'] ?? null, + ]; + } + $frames[0]['file'] = $e->getFile(); + $frames[0]['line'] = $e->getLine(); + + /** @var Frames $frames */ + return $frames; + } + + private static function formatName(string $name): string + { + return strtr($name, ['\\' => '.']); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Export/Http/PsrTransport.php b/vendor/open-telemetry/sdk/Common/Export/Http/PsrTransport.php new file mode 100644 index 000000000..a53e5b80a --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Export/Http/PsrTransport.php @@ -0,0 +1,168 @@ + + */ +final class PsrTransport implements TransportInterface +{ + private ClientInterface $client; + private RequestFactoryInterface $requestFactory; + private StreamFactoryInterface $streamFactory; + + private string $endpoint; + private string $contentType; + private array $headers; + private array $compression; + private int $retryDelay; + private int $maxRetries; + + private bool $closed = false; + + /** + * @psalm-param CONTENT_TYPE $contentType + */ + public function __construct( + ClientInterface $client, + RequestFactoryInterface $requestFactory, + StreamFactoryInterface $streamFactory, + string $endpoint, + string $contentType, + array $headers, + array $compression, + int $retryDelay, + int $maxRetries + ) { + $this->client = $client; + $this->requestFactory = $requestFactory; + $this->streamFactory = $streamFactory; + $this->endpoint = $endpoint; + $this->contentType = $contentType; + $this->headers = $headers; + $this->compression = $compression; + $this->retryDelay = $retryDelay; + $this->maxRetries = $maxRetries; + } + + public function contentType(): string + { + return $this->contentType; + } + + public function send(string $payload, ?CancellationInterface $cancellation = null): FutureInterface + { + if ($this->closed) { + return new ErrorFuture(new BadMethodCallException('Transport closed')); + } + + $body = PsrUtils::encode($payload, $this->compression, $appliedEncodings); + $request = $this->requestFactory + ->createRequest('POST', $this->endpoint) + ->withBody($this->streamFactory->createStream($body)) + ->withHeader('Content-Type', $this->contentType) + ; + if ($appliedEncodings) { + $request = $request->withHeader('Content-Encoding', $appliedEncodings); + } + foreach ($this->headers as $header => $value) { + $request = $request->withAddedHeader($header, $value); + } + + for ($retries = 0;; $retries++) { + $response = null; + $e = null; + + try { + $response = $this->client->sendRequest($request); + if ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300) { + break; + } + + if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 500 && !in_array($response->getStatusCode(), [408, 429], true)) { + throw new RuntimeException($response->getReasonPhrase(), $response->getStatusCode()); + } + } catch (NetworkExceptionInterface $e) { + } catch (Throwable $e) { + return new ErrorFuture($e); + } + + if ($retries >= $this->maxRetries) { + return new ErrorFuture(new RuntimeException('Export retry limit exceeded', 0, $e)); + } + + $delay = PsrUtils::retryDelay($retries, $this->retryDelay, $response); + $sec = (int) $delay; + $nsec = (int) (($delay - $sec) * 1e9); + + /** @psalm-suppress ArgumentTypeCoercion */ + if (time_nanosleep($sec, $nsec) !== true) { + return new ErrorFuture(new RuntimeException('Export cancelled', 0, $e)); + } + } + + assert(isset($response)); + + try { + $body = PsrUtils::decode( + $response->getBody()->__toString(), + self::parseContentEncoding($response), + ); + } catch (Throwable $e) { + return new ErrorFuture($e); + } + + return new CompletedFuture($body); + } + + private static function parseContentEncoding(ResponseInterface $response): array + { + $encodings = []; + foreach (explode(',', $response->getHeaderLine('Content-Encoding')) as $encoding) { + if (($encoding = trim($encoding, " \t")) !== '') { + $encodings[] = strtolower($encoding); + } + } + + return $encodings; + } + + public function shutdown(?CancellationInterface $cancellation = null): bool + { + if ($this->closed) { + return false; + } + + $this->closed = true; + + return true; + } + + public function forceFlush(?CancellationInterface $cancellation = null): bool + { + return !$this->closed; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Export/Http/PsrTransportFactory.php b/vendor/open-telemetry/sdk/Common/Export/Http/PsrTransportFactory.php new file mode 100644 index 000000000..5ef78d82c --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Export/Http/PsrTransportFactory.php @@ -0,0 +1,74 @@ +client = $client; + $this->requestFactory = $requestFactory; + $this->streamFactory = $streamFactory; + } + + /** + * @phan-suppress PhanTypeMismatchArgumentNullable + */ + public function create( + string $endpoint, + string $contentType, + array $headers = [], + $compression = null, + float $timeout = 10., + int $retryDelay = 100, + int $maxRetries = 3, + ?string $cacert = null, + ?string $cert = null, + ?string $key = null + ): PsrTransport { + if (!filter_var($endpoint, FILTER_VALIDATE_URL)) { + throw new InvalidArgumentException(sprintf('Invalid endpoint url "%s"', $endpoint)); + } + assert(!empty($endpoint)); + + return new PsrTransport( + $this->client, + $this->requestFactory, + $this->streamFactory, + $endpoint, + $contentType, + $headers, + PsrUtils::compression($compression), + $retryDelay, + $maxRetries, + ); + } + + public static function discover(): self + { + return new self( + Psr18ClientDiscovery::find(), + Psr17FactoryDiscovery::findRequestFactory(), + Psr17FactoryDiscovery::findStreamFactory(), + ); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Export/Http/PsrUtils.php b/vendor/open-telemetry/sdk/Common/Export/Http/PsrUtils.php new file mode 100644 index 000000000..eaf2f3b47 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Export/Http/PsrUtils.php @@ -0,0 +1,175 @@ +> 1, $delay) / 1000; + + return max($delay, self::parseRetryAfter($response)); + } + + private static function parseRetryAfter(?ResponseInterface $response): int + { + if (!$response || !$retryAfter = $response->getHeaderLine('Retry-After')) { + return 0; + } + + $retryAfter = trim($retryAfter, " \t"); + if ($retryAfter === (string) (int) $retryAfter) { + return (int) $retryAfter; + } + + if (($time = strtotime($retryAfter)) !== false) { + return $time - time(); + } + + return 0; + } + + /** + * @param list $encodings + * @param array|null $appliedEncodings + */ + public static function encode(string $value, array $encodings, ?array &$appliedEncodings = null): string + { + for ($i = 0, $n = count($encodings); $i < $n; $i++) { + if (!$encoder = self::encoder($encodings[$i])) { + unset($encodings[$i]); + + continue; + } + + try { + $value = $encoder($value); + } catch (Throwable $e) { + unset($encodings[$i]); + } + } + + $appliedEncodings = $encodings; + + return $value; + } + + /** + * @param list $encodings + */ + public static function decode(string $value, array $encodings): string + { + for ($i = count($encodings); --$i >= 0;) { + if (strcasecmp($encodings[$i], 'identity') === 0) { + continue; + } + if (!$decoder = self::decoder($encodings[$i])) { + throw new UnexpectedValueException(sprintf('Not supported decompression encoding "%s"', $encodings[$i])); + } + + $value = $decoder($value); + } + + return $value; + } + + /** + * Resolve an array or CSV of compression types to a list + */ + public static function compression($compression): array + { + if (is_array($compression)) { + return $compression; + } + if (!$compression) { + return []; + } + if (strpos($compression, ',') === false) { + return [$compression]; + } + + return array_map('trim', explode(',', $compression)); + } + + private static function encoder(string $encoding): ?callable + { + static $encoders; + + /** @noinspection SpellCheckingInspection */ + $encoders ??= array_map(fn (callable $callable): callable => self::throwOnErrorOrFalse($callable), array_filter([ + TransportFactoryInterface::COMPRESSION_GZIP => 'gzencode', + TransportFactoryInterface::COMPRESSION_DEFLATE => 'gzcompress', + TransportFactoryInterface::COMPRESSION_BROTLI => 'brotli_compress', + ], 'function_exists')); + + return $encoders[$encoding] ?? null; + } + + private static function decoder(string $encoding): ?callable + { + static $decoders; + + /** @noinspection SpellCheckingInspection */ + $decoders ??= array_map(fn (callable $callable): callable => self::throwOnErrorOrFalse($callable), array_filter([ + TransportFactoryInterface::COMPRESSION_GZIP => 'gzdecode', + TransportFactoryInterface::COMPRESSION_DEFLATE => 'gzuncompress', + TransportFactoryInterface::COMPRESSION_BROTLI => 'brotli_uncompress', + ], 'function_exists')); + + return $decoders[$encoding] ?? null; + } + + private static function throwOnErrorOrFalse(callable $callable): callable + { + return static function (...$args) use ($callable) { + set_error_handler(static function (int $errno, string $errstr, string $errfile, int $errline): bool { + throw new ErrorException($errstr, 0, $errno, $errfile, $errline); + }); + + try { + $result = $callable(...$args); + } finally { + restore_error_handler(); + } + + /** @phan-suppress-next-line PhanPossiblyUndeclaredVariable */ + if ($result === false) { + throw new LogicException(); + } + + /** @phan-suppress-next-line PhanPossiblyUndeclaredVariable */ + return $result; + }; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Export/Stream/StreamTransport.php b/vendor/open-telemetry/sdk/Common/Export/Stream/StreamTransport.php new file mode 100644 index 000000000..4b99cf756 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Export/Stream/StreamTransport.php @@ -0,0 +1,97 @@ + + */ +final class StreamTransport implements TransportInterface +{ + /** + * @var resource|null + */ + private $stream; + private string $contentType; + + /** + * @param resource $stream + * + * @psalm-param CONTENT_TYPE $contentType + */ + public function __construct($stream, string $contentType) + { + $this->stream = $stream; + $this->contentType = $contentType; + } + + public function contentType(): string + { + return $this->contentType; + } + + public function send(string $payload, ?CancellationInterface $cancellation = null): FutureInterface + { + if (!$this->stream) { + return new ErrorFuture(new BadMethodCallException('Transport closed')); + } + + set_error_handler(static function (int $errno, string $errstr, string $errfile, int $errline): bool { + throw new ErrorException($errstr, 0, $errno, $errfile, $errline); + }); + + try { + $bytesWritten = fwrite($this->stream, $payload); + } catch (Throwable $e) { + return new ErrorFuture($e); + } finally { + restore_error_handler(); + } + + if ($bytesWritten !== strlen($payload)) { + return new ErrorFuture(new RuntimeException(sprintf('Write failure, wrote %d of %d bytes', $bytesWritten, strlen($payload)))); + } + + return new CompletedFuture(null); + } + + public function shutdown(?CancellationInterface $cancellation = null): bool + { + if (!$this->stream) { + return false; + } + + $flush = @fflush($this->stream); + $this->stream = null; + + return $flush; + } + + public function forceFlush(?CancellationInterface $cancellation = null): bool + { + if (!$this->stream) { + return false; + } + + return @fflush($this->stream); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Export/Stream/StreamTransportFactory.php b/vendor/open-telemetry/sdk/Common/Export/Stream/StreamTransportFactory.php new file mode 100644 index 000000000..59e411318 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Export/Stream/StreamTransportFactory.php @@ -0,0 +1,118 @@ + $headers + * @param string|string[]|null $compression + * + * @psalm-template CONTENT_TYPE of string + * @psalm-param CONTENT_TYPE $contentType + * @psalm-return TransportInterface + */ + public function create( + $endpoint, + string $contentType, + array $headers = [], + $compression = null, + float $timeout = 10., + int $retryDelay = 100, + int $maxRetries = 3, + ?string $cacert = null, + ?string $cert = null, + ?string $key = null + ): TransportInterface { + assert(!empty($endpoint)); + $stream = is_resource($endpoint) + ? $endpoint + : self::createStream( + $endpoint, + $contentType, + $headers, + $timeout, + $cacert, + $cert, + $key, + ); + + return new StreamTransport($stream, $contentType); + } + + /** + * @throws ErrorException + * @return resource + */ + private static function createStream( + string $endpoint, + string $contentType, + array $headers = [], + float $timeout = 10., + ?string $cacert = null, + ?string $cert = null, + ?string $key = null + ) { + $context = stream_context_create([ + 'http' => [ + 'method' => 'POST', + 'header' => self::createHeaderArray($contentType, $headers), + 'timeout' => $timeout, + ], + 'ssl' => [ + 'cafile' => $cacert, + 'local_cert' => $cert, + 'local_pk' => $key, + ], + ]); + + set_error_handler(static function (int $errno, string $errstr, string $errfile, int $errline): bool { + throw new ErrorException($errstr, 0, $errno, $errfile, $errline); + }); + + /** + * @psalm-suppress PossiblyNullArgument + */ + try { + $stream = fopen($endpoint, 'ab', false, $context); + } finally { + restore_error_handler(); + } + + /** @phan-suppress-next-line PhanPossiblyUndeclaredVariable */ + if (!$stream) { + throw new LogicException(sprintf('Failed opening stream "%s"', $endpoint)); + } + + return $stream; + } + + private static function createHeaderArray(string $contentType, array $headers): array + { + $header = []; + $header[] = sprintf('Content-Type: %s', $contentType); + foreach ($headers as $name => $value) { + $header[] = sprintf('%s: %s', $name, implode(', ', (array) $value)); + } + + return $header; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Export/TransportFactoryInterface.php b/vendor/open-telemetry/sdk/Common/Export/TransportFactoryInterface.php new file mode 100644 index 000000000..48e538443 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Export/TransportFactoryInterface.php @@ -0,0 +1,32 @@ + $headers + * @psalm-param string|string[]|null $compression + * @psalm-return TransportInterface + */ + public function create( + string $endpoint, + string $contentType, + array $headers = [], + $compression = null, + float $timeout = 10., + int $retryDelay = 100, + int $maxRetries = 3, + ?string $cacert = null, + ?string $cert = null, + ?string $key = null + ): TransportInterface; +} diff --git a/vendor/open-telemetry/sdk/Common/Export/TransportInterface.php b/vendor/open-telemetry/sdk/Common/Export/TransportInterface.php new file mode 100644 index 000000000..5fb26eff8 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Export/TransportInterface.php @@ -0,0 +1,22 @@ + + */ +final class CompletedFuture implements FutureInterface +{ + /** @var T */ + private $value; + + /** + * @param T $value + */ + public function __construct($value) + { + $this->value = $value; + } + + public function await() + { + return $this->value; + } + + public function map(Closure $closure): FutureInterface + { + $c = $closure; + unset($closure); + + try { + return new CompletedFuture($c($this->value)); + } catch (Throwable $e) { + return new ErrorFuture($e); + } + } + + public function catch(Closure $closure): FutureInterface + { + return $this; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Future/ErrorFuture.php b/vendor/open-telemetry/sdk/Common/Future/ErrorFuture.php new file mode 100644 index 000000000..32cf3d995 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Future/ErrorFuture.php @@ -0,0 +1,40 @@ +throwable = $throwable; + } + + public function await() + { + throw $this->throwable; + } + + public function map(Closure $closure): FutureInterface + { + return $this; + } + + public function catch(Closure $closure): FutureInterface + { + $c = $closure; + unset($closure); + + try { + return new CompletedFuture($c($this->throwable)); + } catch (Throwable $e) { + return new ErrorFuture($e); + } + } +} diff --git a/vendor/open-telemetry/sdk/Common/Future/FutureInterface.php b/vendor/open-telemetry/sdk/Common/Future/FutureInterface.php new file mode 100644 index 000000000..850699bf6 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Future/FutureInterface.php @@ -0,0 +1,34 @@ + + * + * @psalm-suppress InvalidTemplateParam + */ + public function map(Closure $closure): FutureInterface; + + /** + * @psalm-template U + * @psalm-param Closure(\Throwable): U $closure + * @psalm-return FutureInterface + */ + public function catch(Closure $closure): FutureInterface; +} diff --git a/vendor/open-telemetry/sdk/Common/Future/NullCancellation.php b/vendor/open-telemetry/sdk/Common/Future/NullCancellation.php new file mode 100644 index 000000000..5e5b642f9 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Future/NullCancellation.php @@ -0,0 +1,20 @@ +requestFactory = $requestFactory; + $this->responseFactory = $responseFactory; + $this->serverRequestFactory = $serverRequestFactory; + } + + public static function create( + RequestFactoryInterface $requestFactory, + ResponseFactoryInterface $responseFactory, + ServerRequestFactoryInterface $serverRequestFactory + ): self { + return new self($requestFactory, $responseFactory, $serverRequestFactory); + } + + public function createRequest(string $method, $uri): RequestInterface + { + return $this->requestFactory->createRequest($method, $uri); + } + + public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface + { + return $this->responseFactory->createResponse($code, $reasonPhrase); + } + + public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface + { + return $this->serverRequestFactory->createServerRequest($method, $uri, $serverParams); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Http/Psr/Message/MessageFactoryInterface.php b/vendor/open-telemetry/sdk/Common/Http/Psr/Message/MessageFactoryInterface.php new file mode 100644 index 000000000..97258491f --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Http/Psr/Message/MessageFactoryInterface.php @@ -0,0 +1,13 @@ +name = $name; + $this->version = $version; + $this->schemaUrl = $schemaUrl; + $this->attributes = $attributes; + } + + public function getName(): string + { + return $this->name; + } + + public function getVersion(): ?string + { + return $this->version; + } + + public function getSchemaUrl(): ?string + { + return $this->schemaUrl; + } + + public function getAttributes(): AttributesInterface + { + return $this->attributes; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScopeFactory.php b/vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScopeFactory.php new file mode 100644 index 000000000..f1ae7c072 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScopeFactory.php @@ -0,0 +1,31 @@ +attributesFactory = $attributesFactory; + } + + public function create( + string $name, + ?string $version = null, + ?string $schemaUrl = null, + iterable $attributes = [] + ): InstrumentationScopeInterface { + return new InstrumentationScope( + $name, + $version, + $schemaUrl, + $this->attributesFactory->builder($attributes)->build(), + ); + } +} diff --git a/vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScopeFactoryInterface.php b/vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScopeFactoryInterface.php new file mode 100644 index 000000000..78292de58 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Instrumentation/InstrumentationScopeFactoryInterface.php @@ -0,0 +1,15 @@ +build(); + } + + public static function setDefault(?ClockInterface $clock): void + { + self::$default = $clock; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Time/ClockFactoryInterface.php b/vendor/open-telemetry/sdk/Common/Time/ClockFactoryInterface.php new file mode 100644 index 000000000..6d9afde91 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Time/ClockFactoryInterface.php @@ -0,0 +1,16 @@ +clock = $clock; + $this->initialStartTime = $initialStartTime; + } + + public function isRunning(): bool + { + return $this->running; + } + + public function start(): void + { + // resolve start time as early as possible + $startTime = $this->time(); + + if ($this->isRunning()) { + return; + } + + $this->startTime = $startTime; + if (!$this->hasBeenStarted()) { + $this->initialStartTime = $startTime; + } + $this->running = true; + } + + public function stop(): void + { + if (!$this->isRunning()) { + return; + } + + $this->stopTime = $this->time(); + $this->running = false; + } + + public function reset(): void + { + $this->startTime = $this->initialStartTime = $this->isRunning() ? $this->time() : null; + } + + public function getElapsedTime(): int + { + if (!$this->hasBeenStarted()) { + return self::INITIAL_ELAPSED_TIME; + } + + return $this->calculateElapsedTime(); + } + + public function getLastElapsedTime(): int + { + if (!$this->hasBeenStarted()) { + return self::INITIAL_ELAPSED_TIME; + } + + return $this->calculateLastElapsedTime(); + } + + private function time(): int + { + return $this->clock->now(); + } + + private function hasBeenStarted(): bool + { + return $this->initialStartTime !== null; + } + + private function calculateElapsedTime(): int + { + $referenceTime = $this->isRunning() + ? $this->time() + : $this->getStopTime(); + + return $referenceTime - $this->getInitialStartTime(); + } + + private function calculateLastElapsedTime(): int + { + $referenceTime = $this->isRunning() + ? $this->time() + : $this->getStopTime(); + + return $referenceTime - $this->getStartTime(); + } + + private function getInitialStartTime(): ?int + { + return $this->initialStartTime; + } + + private function getStartTime(): ?int + { + return $this->startTime; + } + + private function getStopTime(): ?int + { + return $this->stopTime; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Time/StopWatchFactory.php b/vendor/open-telemetry/sdk/Common/Time/StopWatchFactory.php new file mode 100644 index 000000000..f60c377fc --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Time/StopWatchFactory.php @@ -0,0 +1,44 @@ +clock = $clock ?? ClockFactory::getDefault(); + $this->initialStartTime = $initialStartTime; + } + + public static function create(?ClockInterface $clock = null, ?int $initialStartTime = null): self + { + return new self($clock, $initialStartTime); + } + + public static function fromClockFactory(ClockFactoryInterface $factory, ?int $initialStartTime = null): self + { + return self::create($factory->build(), $initialStartTime); + } + + public function build(): StopWatch + { + return new StopWatch($this->clock, $this->initialStartTime); + } + + public static function getDefault(): StopWatchInterface + { + return self::$default ?? self::$default = self::create()->build(); + } + + public static function setDefault(?StopWatchInterface $default): void + { + self::$default = $default; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Time/StopWatchFactoryInterface.php b/vendor/open-telemetry/sdk/Common/Time/StopWatchFactoryInterface.php new file mode 100644 index 000000000..9750f5769 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Time/StopWatchFactoryInterface.php @@ -0,0 +1,18 @@ + 0) { + return; + } + + self::$referenceTime = self::calculateReferenceTime( + microtime(true), + hrtime(true) + ); + } + + /** + * Calculates the reference time which is later used to calculate the current wall clock time in nanoseconds by adding the current uptime. + */ + private static function calculateReferenceTime(float $wallClockMicroTime, int $upTime): int + { + return ((int) ($wallClockMicroTime * ClockInterface::NANOS_PER_SECOND)) - $upTime; + } +} diff --git a/vendor/open-telemetry/sdk/Common/Time/Util.php b/vendor/open-telemetry/sdk/Common/Time/Util.php new file mode 100644 index 000000000..e1be1f750 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Time/Util.php @@ -0,0 +1,32 @@ +|null */ + private static ?array $handlers = null; + /** @var ArrayAccess|null */ + private static ?ArrayAccess $weakMap = null; + + private array $ids = []; + + private function __construct() + { + } + + public function __destruct() + { + if (!self::$handlers) { + return; + } + foreach ($this->ids as $id) { + unset(self::$handlers[$id]); + } + } + + /** + * Registers a function that will be executed on shutdown. + * + * If the given function is bound to an object, then the function will only + * be executed if the bound object is still referenced on shutdown handler + * invocation. + * + * ```php + * ShutdownHandler::register([$tracerProvider, 'shutdown']); + * ``` + * + * @param callable $shutdownFunction function to register + * + * @see register_shutdown_function + */ + public static function register(callable $shutdownFunction): void + { + self::registerShutdownFunction(); + self::$handlers[] = weaken(closure($shutdownFunction), $target); + + if (!$object = $target) { + return; + } + + self::$weakMap ??= WeakMap::create(); + $handler = self::$weakMap[$object] ??= new self(); + $handler->ids[] = array_key_last(self::$handlers); + } + + private static function registerShutdownFunction(): void + { + if (self::$handlers === null) { + register_shutdown_function(static function (): void { + $handlers = self::$handlers; + self::$handlers = null; + self::$weakMap = null; + + // Push shutdown to end of queue + // @phan-suppress-next-line PhanTypeMismatchArgumentInternal + register_shutdown_function(static function (array $handlers): void { + foreach ($handlers as $handler) { + $handler(); + } + }, $handlers); + }); + } + } +} diff --git a/vendor/open-telemetry/sdk/Common/Util/WeakMap.php b/vendor/open-telemetry/sdk/Common/Util/WeakMap.php new file mode 100644 index 000000000..3b62d6d64 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Util/WeakMap.php @@ -0,0 +1,175 @@ + + */ + private array $objects = []; + + private function __construct() + { + } + + /** + * @return ArrayAccess&Countable&IteratorAggregate + */ + public static function create(): ArrayAccess + { + if (PHP_VERSION_ID >= 80000) { + /** @phan-suppress-next-line PhanUndeclaredClassReference */ + assert(class_exists(\WeakMap::class, false)); + /** @phan-suppress-next-line PhanUndeclaredClassMethod */ + $map = new \WeakMap(); + assert($map instanceof ArrayAccess); + assert($map instanceof Countable); + assert($map instanceof IteratorAggregate); + + return $map; + } + + return new self(); + } + + public function offsetExists($offset): bool + { + if (!is_object($offset)) { + throw new TypeError('WeakMap key must be an object'); + } + + return isset($offset->{self::KEY}[spl_object_id($this)]); + } + + /** + * @phan-suppress PhanUndeclaredClassAttribute + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + if (!is_object($offset)) { + throw new TypeError('WeakMap key must be an object'); + } + if (!$this->contains($offset)) { + throw new Error(sprintf('Object %s#%d not contained in WeakMap', get_class($offset), spl_object_id($offset))); + } + + return $offset->{self::KEY}[spl_object_id($this)]; + } + + public function offsetSet($offset, $value): void + { + if ($offset === null) { + throw new Error('Cannot append to WeakMap'); + } + if (!is_object($offset)) { + throw new TypeError('WeakMap key must be an object'); + } + if (!$this->contains($offset)) { + $this->expunge(); + } + + $offset->{self::KEY}[spl_object_id($this)] = $value; + $this->objects[spl_object_id($offset)] = WeakReference::create($offset); + } + + public function offsetUnset($offset): void + { + if (!is_object($offset)) { + throw new TypeError('WeakMap key must be an object'); + } + if (!$this->contains($offset)) { + return; + } + + unset( + $offset->{self::KEY}[spl_object_id($this)], + $this->objects[spl_object_id($offset)], + ); + if (!$offset->{self::KEY}) { + unset($offset->{self::KEY}); + } + } + + public function count(): int + { + $this->expunge(); + + return count($this->objects); + } + + public function getIterator(): Traversable + { + $this->expunge(); + + foreach ($this->objects as $reference) { + if (($object = $reference->get()) && $this->contains($object)) { + yield $object => $this[$object]; + } + } + } + + public function __debugInfo(): array + { + $debugInfo = []; + foreach ($this as $key => $value) { + $debugInfo[] = ['key' => $key, 'value' => $value]; + } + + return $debugInfo; + } + + public function __destruct() + { + foreach ($this->objects as $reference) { + if ($object = $reference->get()) { + unset($this[$object]); + } + } + } + + private function contains(object $offset): bool + { + $reference = $this->objects[spl_object_id($offset)] ?? null; + if ($reference && $reference->get() === $offset) { + return true; + } + + unset($this->objects[spl_object_id($offset)]); + + return false; + } + + private function expunge(): void + { + foreach ($this->objects as $id => $reference) { + if (!$reference->get()) { + unset($this->objects[$id]); + } + } + } +} diff --git a/vendor/open-telemetry/sdk/Common/Util/functions.php b/vendor/open-telemetry/sdk/Common/Util/functions.php new file mode 100644 index 000000000..f4fb13b80 --- /dev/null +++ b/vendor/open-telemetry/sdk/Common/Util/functions.php @@ -0,0 +1,52 @@ +getClosureThis()) { + return $closure; + } + + $scope = $reflection->getClosureScopeClass(); + $name = $reflection->getShortName(); + if ($name !== '{closure}') { + /** @psalm-suppress InvalidScope @phpstan-ignore-next-line @phan-suppress-next-line PhanUndeclaredThis */ + $closure = fn (...$args) => $this->$name(...$args); + if ($scope !== null) { + $closure = $closure->bindTo(null, $scope->name); + } + } + + static $placeholder; + $placeholder ??= new stdClass(); + $closure = $closure->bindTo($placeholder); + + $ref = WeakReference::create($target); + + /** @psalm-suppress PossiblyInvalidFunctionCall */ + return $scope && get_class($target) === $scope->name && !$scope->isInternal() + ? static fn (...$args) => ($obj = $ref->get()) ? $closure->call($obj, ...$args) : null + : static fn (...$args) => ($obj = $ref->get()) ? $closure->bindTo($obj)(...$args) : null; +} diff --git a/vendor/open-telemetry/sdk/Logs/Exporter/ConsoleExporter.php b/vendor/open-telemetry/sdk/Logs/Exporter/ConsoleExporter.php new file mode 100644 index 000000000..e34fa308c --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/Exporter/ConsoleExporter.php @@ -0,0 +1,106 @@ +transport = $transport; + } + + /** + * @param iterable $batch + */ + public function export(iterable $batch, ?CancellationInterface $cancellation = null): FutureInterface + { + $resource = null; + $scopes = []; + foreach ($batch as $record) { + if (!$resource) { + $resource = $this->convertResource($record->getResource()); + } + $key = $this->scopeKey($record->getInstrumentationScope()); + if (!array_key_exists($key, $scopes)) { + $scopes[$key] = $this->convertInstrumentationScope($record->getInstrumentationScope()); + } + $scopes[$key]['logs'][] = $this->convertLogRecord($record); + } + $output = [ + 'resource' => $resource, + 'scopes' => array_values($scopes), + ]; + $this->transport->send(json_encode($output, JSON_PRETTY_PRINT)); + + return new CompletedFuture(true); + } + + public function forceFlush(?CancellationInterface $cancellation = null): bool + { + return true; + } + + public function shutdown(?CancellationInterface $cancellation = null): bool + { + return true; + } + private function convertLogRecord(ReadableLogRecord $record): array + { + $spanContext = $record->getSpanContext(); + + return [ + 'timestamp' => $record->getTimestamp(), + 'observed_timestamp' => $record->getObservedTimestamp(), + 'severity_number' => $record->getSeverityNumber(), + 'severity_text' => $record->getSeverityText(), + 'body' => $record->getBody(), + 'trace_id' => $spanContext !== null ? $spanContext->getTraceId() : '', + 'span_id' => $spanContext !== null ? $spanContext->getSpanId() : '', + 'trace_flags' => $spanContext !== null ? $spanContext->getTraceFlags() : null, + 'attributes' => $record->getAttributes()->toArray(), + 'dropped_attributes_count' => $record->getAttributes()->getDroppedAttributesCount(), + ]; + } + + private function convertResource(ResourceInfo $resource): array + { + return [ + 'attributes' => $resource->getAttributes()->toArray(), + 'dropped_attributes_count' => $resource->getAttributes()->getDroppedAttributesCount(), + ]; + } + + private function scopeKey(InstrumentationScopeInterface $scope): string + { + return serialize([$scope->getName(), $scope->getVersion(), $scope->getSchemaUrl(), $scope->getAttributes()]); + } + + private function convertInstrumentationScope(InstrumentationScopeInterface $scope): array + { + return [ + 'name' => $scope->getName(), + 'version' => $scope->getVersion(), + 'attributes' => $scope->getAttributes()->toArray(), + 'dropped_attributes_count' => $scope->getAttributes()->getDroppedAttributesCount(), + 'schema_url' => $scope->getSchemaUrl(), + 'logs' => [], + ]; + } +} diff --git a/vendor/open-telemetry/sdk/Logs/Exporter/ConsoleExporterFactory.php b/vendor/open-telemetry/sdk/Logs/Exporter/ConsoleExporterFactory.php new file mode 100644 index 000000000..a959540a0 --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/Exporter/ConsoleExporterFactory.php @@ -0,0 +1,19 @@ +create('php://stdout', 'application/json'); + + return new ConsoleExporter($transport); + } +} diff --git a/vendor/open-telemetry/sdk/Logs/Exporter/InMemoryExporter.php b/vendor/open-telemetry/sdk/Logs/Exporter/InMemoryExporter.php new file mode 100644 index 000000000..dca0531f3 --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/Exporter/InMemoryExporter.php @@ -0,0 +1,48 @@ +storage = $storage ?? new ArrayObject(); + } + + /** + * @inheritDoc + */ + public function export(iterable $batch, ?CancellationInterface $cancellation = null): FutureInterface + { + foreach ($batch as $record) { + $this->storage[] = $record; + } + + return new CompletedFuture(true); + } + + public function forceFlush(?CancellationInterface $cancellation = null): bool + { + return true; + } + + public function shutdown(?CancellationInterface $cancellation = null): bool + { + return true; + } + + public function getStorage(): ArrayObject + { + return $this->storage; + } +} diff --git a/vendor/open-telemetry/sdk/Logs/Exporter/InMemoryExporterFactory.php b/vendor/open-telemetry/sdk/Logs/Exporter/InMemoryExporterFactory.php new file mode 100644 index 000000000..6f24defe0 --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/Exporter/InMemoryExporterFactory.php @@ -0,0 +1,16 @@ +create(); + } +} diff --git a/vendor/open-telemetry/sdk/Logs/LogRecordExporterFactoryInterface.php b/vendor/open-telemetry/sdk/Logs/LogRecordExporterFactoryInterface.php new file mode 100644 index 000000000..523bec1ba --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/LogRecordExporterFactoryInterface.php @@ -0,0 +1,10 @@ + $batch + */ + public function export(iterable $batch, ?CancellationInterface $cancellation = null): FutureInterface; + public function forceFlush(?CancellationInterface $cancellation = null): bool; + public function shutdown(?CancellationInterface $cancellation = null): bool; +} diff --git a/vendor/open-telemetry/sdk/Logs/LogRecordLimits.php b/vendor/open-telemetry/sdk/Logs/LogRecordLimits.php new file mode 100644 index 000000000..9f71e62ee --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/LogRecordLimits.php @@ -0,0 +1,29 @@ +attributesFactory = $attributesFactory; + } + + public function getAttributeFactory(): AttributesFactoryInterface + { + return $this->attributesFactory; + } +} diff --git a/vendor/open-telemetry/sdk/Logs/LogRecordLimitsBuilder.php b/vendor/open-telemetry/sdk/Logs/LogRecordLimitsBuilder.php new file mode 100644 index 000000000..3aa5217ef --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/LogRecordLimitsBuilder.php @@ -0,0 +1,58 @@ +attributeCountLimit = $attributeCountLimit; + + return $this; + } + + /** + * @param int $attributeValueLengthLimit Maximum allowed attribute value length + */ + public function setAttributeValueLengthLimit(int $attributeValueLengthLimit): LogRecordLimitsBuilder + { + $this->attributeValueLengthLimit = $attributeValueLengthLimit; + + return $this; + } + + /** + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#attribute-limits + */ + public function build(): LogRecordLimits + { + $attributeCountLimit = $this->attributeCountLimit + ?: Configuration::getInt(Variables::OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT); + $attributeValueLengthLimit = $this->attributeValueLengthLimit + ?: Configuration::getInt(Variables::OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT); + + if ($attributeValueLengthLimit === PHP_INT_MAX) { + $attributeValueLengthLimit = null; + } + + $attributesFactory = Attributes::factory($attributeCountLimit, $attributeValueLengthLimit); + + return new LogRecordLimits($attributesFactory); + } +} diff --git a/vendor/open-telemetry/sdk/Logs/LogRecordProcessorFactory.php b/vendor/open-telemetry/sdk/Logs/LogRecordProcessorFactory.php new file mode 100644 index 000000000..dec463735 --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/LogRecordProcessorFactory.php @@ -0,0 +1,62 @@ +createProcessor($name, $exporter, $meterProvider); + } + + switch (count($processors)) { + case 0: + return NoopLogRecordProcessor::getInstance(); + case 1: + return $processors[0]; + default: + return new MultiLogRecordProcessor($processors); + } + } + + private function createProcessor(string $name, LogRecordExporterInterface $exporter, ?MeterProviderInterface $meterProvider = null): LogRecordProcessorInterface + { + switch ($name) { + case KnownValues::VALUE_BATCH: + return new BatchLogRecordProcessor( + $exporter, + ClockFactory::getDefault(), + Configuration::getInt(Variables::OTEL_BLRP_MAX_QUEUE_SIZE), + Configuration::getInt(Variables::OTEL_BLRP_SCHEDULE_DELAY), + Configuration::getInt(Variables::OTEL_BLRP_EXPORT_TIMEOUT), + Configuration::getInt(Variables::OTEL_BLRP_MAX_EXPORT_BATCH_SIZE), + true, + $meterProvider, + ); + case KnownValues::VALUE_SIMPLE: + return new SimpleLogRecordProcessor($exporter); + case Values::VALUE_NOOP: + case Values::VALUE_NONE: + return NoopLogRecordProcessor::getInstance(); + default: + throw new InvalidArgumentException('Unknown processor: ' . $name); + } + } +} diff --git a/vendor/open-telemetry/sdk/Logs/LogRecordProcessorInterface.php b/vendor/open-telemetry/sdk/Logs/LogRecordProcessorInterface.php new file mode 100644 index 000000000..1977d48fd --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/LogRecordProcessorInterface.php @@ -0,0 +1,15 @@ +loggerSharedState = $loggerSharedState; + $this->scope = $scope; + } + + public function emit(LogRecord $logRecord): void + { + $readWriteLogRecord = new ReadWriteLogRecord($this->scope, $this->loggerSharedState, $logRecord); + // @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/sdk.md#onemit + $this->loggerSharedState->getProcessor()->onEmit( + $readWriteLogRecord, + $readWriteLogRecord->getContext(), + ); + } +} diff --git a/vendor/open-telemetry/sdk/Logs/LoggerProvider.php b/vendor/open-telemetry/sdk/Logs/LoggerProvider.php new file mode 100644 index 000000000..f0a8266c1 --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/LoggerProvider.php @@ -0,0 +1,56 @@ +loggerSharedState = new LoggerSharedState( + $resource ?? ResourceInfoFactory::defaultResource(), + (new LogRecordLimitsBuilder())->build(), + $processor + ); + $this->instrumentationScopeFactory = $instrumentationScopeFactory; + } + + /** + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/sdk.md#logger-creation + */ + public function getLogger(string $name, ?string $version = null, ?string $schemaUrl = null, iterable $attributes = []): LoggerInterface + { + if ($this->loggerSharedState->hasShutdown()) { + return NoopLogger::getInstance(); + } + $scope = $this->instrumentationScopeFactory->create($name, $version, $schemaUrl, $attributes); + + return new Logger($this->loggerSharedState, $scope); + } + + public function shutdown(CancellationInterface $cancellation = null): bool + { + return $this->loggerSharedState->shutdown($cancellation); + } + + public function forceFlush(CancellationInterface $cancellation = null): bool + { + return $this->loggerSharedState->forceFlush($cancellation); + } + + public static function builder(): LoggerProviderBuilder + { + return new LoggerProviderBuilder(); + } +} diff --git a/vendor/open-telemetry/sdk/Logs/LoggerProviderBuilder.php b/vendor/open-telemetry/sdk/Logs/LoggerProviderBuilder.php new file mode 100644 index 000000000..37c56245c --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/LoggerProviderBuilder.php @@ -0,0 +1,55 @@ + + */ + private array $processors = []; + private ?ResourceInfo $resource = null; + + public function addLogRecordProcessor(LogRecordProcessorInterface $processor): self + { + $this->processors[] = $processor; + + return $this; + } + + public function setResource(ResourceInfo $resource): self + { + $this->resource = $resource; + + return $this; + } + + public function build(): LoggerProviderInterface + { + return new LoggerProvider( + $this->buildProcessor(), + new InstrumentationScopeFactory(Attributes::factory()), + $this->resource + ); + } + + private function buildProcessor(): LogRecordProcessorInterface + { + switch (count($this->processors)) { + case 0: + return NoopLogRecordProcessor::getInstance(); + case 1: + return $this->processors[0]; + default: + return new MultiLogRecordProcessor($this->processors); + } + } +} diff --git a/vendor/open-telemetry/sdk/Logs/LoggerProviderFactory.php b/vendor/open-telemetry/sdk/Logs/LoggerProviderFactory.php new file mode 100644 index 000000000..3d0e965fd --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/LoggerProviderFactory.php @@ -0,0 +1,24 @@ +create(); + $processor = (new LogRecordProcessorFactory())->create($exporter, $meterProvider); + $instrumentationScopeFactory = new InstrumentationScopeFactory((new LogRecordLimitsBuilder())->build()->getAttributeFactory()); + + return new LoggerProvider($processor, $instrumentationScopeFactory); + } +} diff --git a/vendor/open-telemetry/sdk/Logs/LoggerProviderInterface.php b/vendor/open-telemetry/sdk/Logs/LoggerProviderInterface.php new file mode 100644 index 000000000..5debb13cc --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/LoggerProviderInterface.php @@ -0,0 +1,13 @@ +resource = $resource; + $this->limits = $limits; + $this->processor = $processor; + } + public function hasShutdown(): bool + { + return null !== $this->shutdownResult; + } + + public function getResource(): ResourceInfo + { + return $this->resource; + } + + public function getProcessor(): LogRecordProcessorInterface + { + return $this->processor; + } + + public function getLogRecordLimits(): LogRecordLimits + { + return $this->limits; + } + + public function shutdown(?CancellationInterface $cancellation = null): bool + { + if ($this->shutdownResult !== null) { + return $this->shutdownResult; + } + $this->shutdownResult = $this->processor->shutdown($cancellation); + + return $this->shutdownResult; + } + + public function forceFlush(?CancellationInterface $cancellation = null): bool + { + return $this->processor->forceFlush($cancellation); + } +} diff --git a/vendor/open-telemetry/sdk/Logs/NoopLoggerProvider.php b/vendor/open-telemetry/sdk/Logs/NoopLoggerProvider.php new file mode 100644 index 000000000..819e02ee5 --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/NoopLoggerProvider.php @@ -0,0 +1,33 @@ + 'batching']; + private const ATTRIBUTES_QUEUED = self::ATTRIBUTES_PROCESSOR + ['state' => 'queued']; + private const ATTRIBUTES_PENDING = self::ATTRIBUTES_PROCESSOR + ['state' => 'pending']; + private const ATTRIBUTES_PROCESSED = self::ATTRIBUTES_PROCESSOR + ['state' => 'processed']; + private const ATTRIBUTES_DROPPED = self::ATTRIBUTES_PROCESSOR + ['state' => 'dropped']; + private const ATTRIBUTES_FREE = self::ATTRIBUTES_PROCESSOR + ['state' => 'free']; + + private LogRecordExporterInterface $exporter; + private ClockInterface $clock; + private int $maxQueueSize; + private int $scheduledDelayNanos; + private int $maxExportBatchSize; + private bool $autoFlush; + private ContextInterface $exportContext; + + private ?int $nextScheduledRun = null; + private bool $running = false; + private int $dropped = 0; + private int $processed = 0; + private int $batchId = 0; + private int $queueSize = 0; + /** @var list */ + private array $batch = []; + /** @var SplQueue> */ + private SplQueue $queue; + /** @var SplQueue */ + private SplQueue $flush; + + private bool $closed = false; + + public function __construct( + LogRecordExporterInterface $exporter, + ClockInterface $clock, + int $maxQueueSize = self::DEFAULT_MAX_QUEUE_SIZE, + int $scheduledDelayMillis = self::DEFAULT_SCHEDULE_DELAY, + int $exportTimeoutMillis = self::DEFAULT_EXPORT_TIMEOUT, + int $maxExportBatchSize = self::DEFAULT_MAX_EXPORT_BATCH_SIZE, + bool $autoFlush = true, + ?MeterProviderInterface $meterProvider = null + ) { + if ($maxQueueSize <= 0) { + throw new InvalidArgumentException(sprintf('Maximum queue size (%d) must be greater than zero', $maxQueueSize)); + } + if ($scheduledDelayMillis <= 0) { + throw new InvalidArgumentException(sprintf('Scheduled delay (%d) must be greater than zero', $scheduledDelayMillis)); + } + if ($exportTimeoutMillis <= 0) { + throw new InvalidArgumentException(sprintf('Export timeout (%d) must be greater than zero', $exportTimeoutMillis)); + } + if ($maxExportBatchSize <= 0) { + throw new InvalidArgumentException(sprintf('Maximum export batch size (%d) must be greater than zero', $maxExportBatchSize)); + } + if ($maxExportBatchSize > $maxQueueSize) { + throw new InvalidArgumentException(sprintf('Maximum export batch size (%d) must be less than or equal to maximum queue size (%d)', $maxExportBatchSize, $maxQueueSize)); + } + + $this->exporter = $exporter; + $this->clock = $clock; + $this->maxQueueSize = $maxQueueSize; + $this->scheduledDelayNanos = $scheduledDelayMillis * 1_000_000; + $this->maxExportBatchSize = $maxExportBatchSize; + $this->autoFlush = $autoFlush; + + $this->exportContext = Context::getCurrent(); + $this->queue = new SplQueue(); + $this->flush = new SplQueue(); + + if ($meterProvider === null) { + return; + } + + $meter = $meterProvider->getMeter('io.opentelemetry.sdk'); + $meter + ->createObservableUpDownCounter( + 'otel.logs.log_processor.logs', + '{logs}', + 'The number of log records received by the processor', + ) + ->observe(function (ObserverInterface $observer): void { + $queued = $this->queue->count() * $this->maxExportBatchSize + count($this->batch); + $pending = $this->queueSize - $queued; + $processed = $this->processed; + $dropped = $this->dropped; + + $observer->observe($queued, self::ATTRIBUTES_QUEUED); + $observer->observe($pending, self::ATTRIBUTES_PENDING); + $observer->observe($processed, self::ATTRIBUTES_PROCESSED); + $observer->observe($dropped, self::ATTRIBUTES_DROPPED); + }); + $meter + ->createObservableUpDownCounter( + 'otel.logs.log_processor.queue.limit', + '{logs}', + 'The queue size limit', + ) + ->observe(function (ObserverInterface $observer): void { + $observer->observe($this->maxQueueSize, self::ATTRIBUTES_PROCESSOR); + }); + $meter + ->createObservableUpDownCounter( + 'otel.logs.log_processor.queue.usage', + '{logs}', + 'The current queue usage', + ) + ->observe(function (ObserverInterface $observer): void { + $queued = $this->queue->count() * $this->maxExportBatchSize + count($this->batch); + $pending = $this->queueSize - $queued; + $free = $this->maxQueueSize - $this->queueSize; + + $observer->observe($queued, self::ATTRIBUTES_QUEUED); + $observer->observe($pending, self::ATTRIBUTES_PENDING); + $observer->observe($free, self::ATTRIBUTES_FREE); + }); + } + + public function onEmit(ReadWriteLogRecord $record, ?ContextInterface $context = null): void + { + if ($this->closed) { + return; + } + + if ($this->queueSize === $this->maxQueueSize) { + $this->dropped++; + + return; + } + + $this->queueSize++; + $this->batch[] = $record; + $this->nextScheduledRun ??= $this->clock->now() + $this->scheduledDelayNanos; + + if (count($this->batch) === $this->maxExportBatchSize) { + $this->enqueueBatch(); + } + if ($this->autoFlush) { + $this->flush(); + } + } + + public function forceFlush(?CancellationInterface $cancellation = null): bool + { + if ($this->closed) { + return false; + } + + return $this->flush(__FUNCTION__, $cancellation); + } + + public function shutdown(?CancellationInterface $cancellation = null): bool + { + if ($this->closed) { + return false; + } + + $this->closed = true; + + return $this->flush(__FUNCTION__, $cancellation); + } + + private function flush(?string $flushMethod = null, ?CancellationInterface $cancellation = null): bool + { + if ($flushMethod !== null) { + $flushId = $this->batchId + $this->queue->count() + (int) (bool) $this->batch; + $this->flush->enqueue([$flushId, $flushMethod, $cancellation, !$this->running, Context::getCurrent()]); + } + + if ($this->running) { + return false; + } + + $success = true; + $exception = null; + $this->running = true; + + try { + for (;;) { + while (!$this->flush->isEmpty() && $this->flush->bottom()[0] <= $this->batchId) { + [, $flushMethod, $cancellation, $propagateResult, $context] = $this->flush->dequeue(); + $scope = $context->activate(); + + try { + $result = $this->exporter->$flushMethod($cancellation); + if ($propagateResult) { + $success = $result; + } + } catch (Throwable $e) { + if ($propagateResult) { + $exception = $e; + } else { + self::logError(sprintf('Unhandled %s error', $flushMethod), ['exception' => $e]); + } + } finally { + $scope->detach(); + } + } + + if (!$this->shouldFlush()) { + break; + } + + if ($this->queue->isEmpty()) { + $this->enqueueBatch(); + } + $batchSize = count($this->queue->bottom()); + $this->batchId++; + $scope = $this->exportContext->activate(); + + try { + $this->exporter->export($this->queue->dequeue())->await(); + } catch (Throwable $e) { + self::logError('Unhandled export error', ['exception' => $e]); + } finally { + $this->processed += $batchSize; + $this->queueSize -= $batchSize; + $scope->detach(); + } + } + } finally { + $this->running = false; + } + + if ($exception !== null) { + throw $exception; + } + + return $success; + } + + private function shouldFlush(): bool + { + return !$this->flush->isEmpty() + || $this->autoFlush && !$this->queue->isEmpty() + || $this->autoFlush && $this->nextScheduledRun !== null && $this->clock->now() > $this->nextScheduledRun; + } + + private function enqueueBatch(): void + { + assert($this->batch !== []); + + $this->queue->enqueue($this->batch); + $this->batch = []; + $this->nextScheduledRun = null; + } +} diff --git a/vendor/open-telemetry/sdk/Logs/Processor/MultiLogRecordProcessor.php b/vendor/open-telemetry/sdk/Logs/Processor/MultiLogRecordProcessor.php new file mode 100644 index 000000000..753a75df8 --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/Processor/MultiLogRecordProcessor.php @@ -0,0 +1,62 @@ +processors[] = $processor; + } + } + + public function onEmit(ReadWriteLogRecord $record, ?ContextInterface $context = null): void + { + foreach ($this->processors as $processor) { + $processor->onEmit($record, $context); + } + } + + /** + * Returns `true` if all processors shut down successfully, else `false` + * Subsequent calls to `shutdown` are a no-op. + */ + public function shutdown(?CancellationInterface $cancellation = null): bool + { + $result = true; + foreach ($this->processors as $processor) { + if (!$processor->shutdown($cancellation)) { + $result = false; + } + } + + return $result; + } + + /** + * Returns `true` if all processors flush successfully, else `false`. + */ + public function forceFlush(?CancellationInterface $cancellation = null): bool + { + $result = true; + foreach ($this->processors as $processor) { + if (!$processor->forceFlush($cancellation)) { + $result = false; + } + } + + return $result; + } +} diff --git a/vendor/open-telemetry/sdk/Logs/Processor/NoopLogRecordProcessor.php b/vendor/open-telemetry/sdk/Logs/Processor/NoopLogRecordProcessor.php new file mode 100644 index 000000000..7028052e1 --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/Processor/NoopLogRecordProcessor.php @@ -0,0 +1,37 @@ +exporter = $exporter; + } + + /** + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/sdk.md#onemit + */ + public function onEmit(ReadWriteLogRecord $record, ?ContextInterface $context = null): void + { + $this->exporter->export([$record]); + } + + public function shutdown(?CancellationInterface $cancellation = null): bool + { + return $this->exporter->shutdown($cancellation); + } + + public function forceFlush(?CancellationInterface $cancellation = null): bool + { + return $this->exporter->forceFlush($cancellation); + } +} diff --git a/vendor/open-telemetry/sdk/Logs/PsrSeverityMapperInterface.php b/vendor/open-telemetry/sdk/Logs/PsrSeverityMapperInterface.php new file mode 100644 index 000000000..3bb288c56 --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/PsrSeverityMapperInterface.php @@ -0,0 +1,50 @@ + 7, + // Interesting events. Examples: User logs in, SQL logs. + PsrLogLevel::INFO => 6, + // Normal but significant events. + PsrLogLevel::NOTICE => 5, + // Exceptional occurrences that are not errors. Examples: Use of deprecated APIs, poor use of an API, + // undesirable things that are not necessarily wrong. + PsrLogLevel::WARNING => 4, + // Runtime errors that do not require immediate action but should typically be logged and monitored. + PsrLogLevel::ERROR => 3, + // Critical conditions. Example: Application component unavailable, unexpected exception. + PsrLogLevel::CRITICAL => 2, + // Action must be taken immediately. Example: Entire website down, database unavailable, etc. + // This should trigger the alerts and wake you up. + PsrLogLevel::ALERT => 1, + // Emergency: system is unusable. + PsrLogLevel::EMERGENCY => 0, + ]; + + /** + * Mappig of OpenTelemetry SeverityNumber to PsrLogLevel. + * @see: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/specification/logs/data-model.md#field-severitynumber + */ + public const SEVERITY_NUMBER = [ + PsrLogLevel::DEBUG => 5, + PsrLogLevel::INFO => 9, + PsrLogLevel::NOTICE => 10, + PsrLogLevel::WARNING => 13, + PsrLogLevel::ERROR => 17, + PsrLogLevel::CRITICAL => 18, + PsrLogLevel::ALERT => 21, + PsrLogLevel::EMERGENCY => 22, + ]; +} diff --git a/vendor/open-telemetry/sdk/Logs/ReadWriteLogRecord.php b/vendor/open-telemetry/sdk/Logs/ReadWriteLogRecord.php new file mode 100644 index 000000000..9bb4b1564 --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/ReadWriteLogRecord.php @@ -0,0 +1,9 @@ +scope = $scope; + $this->loggerSharedState = $loggerSharedState; + + parent::__construct($logRecord->body); + $this->timestamp = $logRecord->timestamp; + $this->observedTimestamp = $logRecord->observedTimestamp + ?? (int) (microtime(true) * LogRecord::NANOS_PER_SECOND); + $this->context = $logRecord->context; + $context = $this->context ?? Context::getCurrent(); + $this->spanContext = Span::fromContext($context)->getContext(); + $this->severityNumber = $logRecord->severityNumber; + $this->severityText = $logRecord->severityText; + + //convert attributes now so that excess data is not sent to processors + $this->convertedAttributes = $this->loggerSharedState + ->getLogRecordLimits() + ->getAttributeFactory() + ->builder($logRecord->attributes, new LogRecordAttributeValidator()) + ->build(); + } + + public function getInstrumentationScope(): InstrumentationScopeInterface + { + return $this->scope; + } + + public function getResource(): ResourceInfo + { + return $this->loggerSharedState->getResource(); + } + + public function getTimestamp(): ?int + { + return $this->timestamp; + } + + public function getObservedTimestamp(): ?int + { + return $this->observedTimestamp; + } + + public function getContext(): ?ContextInterface + { + return $this->context; + } + + public function getSpanContext(): ?SpanContextInterface + { + return $this->spanContext; + } + + public function getSeverityNumber(): ?int + { + return $this->severityNumber; + } + + public function getSeverityText(): ?string + { + return $this->severityText; + } + + /** + * @return mixed|null + */ + public function getBody() + { + return $this->body; + } + + public function getAttributes(): AttributesInterface + { + return $this->convertedAttributes; + } +} diff --git a/vendor/open-telemetry/sdk/Logs/SimplePsrFileLogger.php b/vendor/open-telemetry/sdk/Logs/SimplePsrFileLogger.php new file mode 100644 index 000000000..9d9d55de6 --- /dev/null +++ b/vendor/open-telemetry/sdk/Logs/SimplePsrFileLogger.php @@ -0,0 +1,83 @@ +filename = $filename; + $this->loggerName = $loggerName; + } + + /** + * @psalm-suppress MoreSpecificImplementedParamType + */ + public function log($level, $message, array $context = []): void + { + $level = strtolower($level); + + if (!in_array($level, self::getLogLevels(), true)) { + throw new InvalidArgumentException( + sprintf('Invalid Log level: "%s"', $level) + ); + } + + file_put_contents($this->filename, $this->formatLog((string) $level, (string) $message, $context), FILE_APPEND); + } + + /** + * @param string $level + * @param string $message + * @param array $context + * @return string + */ + private function formatLog(string $level, string $message, array $context = []): string + { + try { + $encodedContext = json_encode($context, JSON_THROW_ON_ERROR); + } catch (Throwable $t) { + $encodedContext = sprintf('(Could not encode context: %s)', $t->getMessage()); + } + + return sprintf( + '[%s] %s %s: %s %s%s', + date(DATE_RFC3339_EXTENDED), + $this->loggerName, + $level, + $message, + $encodedContext, + PHP_EOL + ); + } + + /** + * @return array + */ + private static function getLogLevels(): array + { + return self::$logLevels ?? self::$logLevels = (new ReflectionClass(LogLevel::class))->getConstants(); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Aggregation/ExplicitBucketHistogramAggregation.php b/vendor/open-telemetry/sdk/Metrics/Aggregation/ExplicitBucketHistogramAggregation.php new file mode 100644 index 000000000..d68ecd830 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Aggregation/ExplicitBucketHistogramAggregation.php @@ -0,0 +1,167 @@ + + */ +final class ExplicitBucketHistogramAggregation implements AggregationInterface +{ + /** + * @var list + * @readonly + */ + public array $boundaries; + + /** + * @param list $boundaries strictly ascending histogram bucket boundaries + */ + public function __construct(array $boundaries) + { + $this->boundaries = $boundaries; + } + + public function initialize(): ExplicitBucketHistogramSummary + { + return new ExplicitBucketHistogramSummary( + 0, + 0, + +INF, + -INF, + array_fill(0, count($this->boundaries) + 1, 0), + ); + } + + /** + * @param ExplicitBucketHistogramSummary $summary + */ + public function record($summary, $value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): void + { + $boundariesCount = count($this->boundaries); + for ($i = 0; $i < $boundariesCount && $this->boundaries[$i] < $value; $i++) { + } + $summary->count++; + $summary->sum += $value; + $summary->min = self::min($value, $summary->min); + $summary->max = self::max($value, $summary->max); + $summary->buckets[$i]++; + } + + /** + * @param ExplicitBucketHistogramSummary $left + * @param ExplicitBucketHistogramSummary $right + */ + public function merge($left, $right): ExplicitBucketHistogramSummary + { + $count = $left->count + $right->count; + $sum = $left->sum + $right->sum; + $min = self::min($left->min, $right->min); + $max = self::max($left->max, $right->max); + $buckets = $right->buckets; + foreach ($left->buckets as $i => $bucketCount) { + $buckets[$i] += $bucketCount; + } + + return new ExplicitBucketHistogramSummary( + $count, + $sum, + $min, + $max, + $buckets, + ); + } + + /** + * @param ExplicitBucketHistogramSummary $left + * @param ExplicitBucketHistogramSummary $right + */ + public function diff($left, $right): ExplicitBucketHistogramSummary + { + $count = -$left->count + $right->count; + $sum = -$left->sum + $right->sum; + $min = $left->min > $right->min ? $right->min : NAN; + $max = $left->max < $right->max ? $right->max : NAN; + $buckets = $right->buckets; + foreach ($left->buckets as $i => $bucketCount) { + $buckets[$i] -= $bucketCount; + } + + return new ExplicitBucketHistogramSummary( + $count, + $sum, + $min, + $max, + $buckets, + ); + } + + /** + * @param array $summaries + */ + public function toData( + array $attributes, + array $summaries, + array $exemplars, + int $startTimestamp, + int $timestamp, + $temporality + ): Data\Histogram { + $dataPoints = []; + foreach ($attributes as $key => $dataPointAttributes) { + if ($summaries[$key]->count === 0) { + continue; + } + + $dataPoints[] = new Data\HistogramDataPoint( + $summaries[$key]->count, + $summaries[$key]->sum, + $summaries[$key]->min, + $summaries[$key]->max, + $summaries[$key]->buckets, + $this->boundaries, + $dataPointAttributes, + $startTimestamp, + $timestamp, + $exemplars[$key] ?? [], + ); + } + + return new Data\Histogram( + $dataPoints, + $temporality, + ); + } + + /** + * @param float|int $left + * @param float|int $right + * @return float|int + */ + private static function min($left, $right) + { + /** @noinspection PhpConditionAlreadyCheckedInspection */ + return $left <= $right ? $left : ($right <= $left ? $right : NAN); + } + + /** + * @param float|int $left + * @param float|int $right + * @return float|int + */ + private static function max($left, $right) + { + /** @noinspection PhpConditionAlreadyCheckedInspection */ + return $left >= $right ? $left : ($right >= $left ? $right : NAN); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Aggregation/ExplicitBucketHistogramSummary.php b/vendor/open-telemetry/sdk/Metrics/Aggregation/ExplicitBucketHistogramSummary.php new file mode 100644 index 000000000..1878a34a0 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Aggregation/ExplicitBucketHistogramSummary.php @@ -0,0 +1,40 @@ +count = $count; + $this->sum = $sum; + $this->min = $min; + $this->max = $max; + $this->buckets = $buckets; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Aggregation/LastValueAggregation.php b/vendor/open-telemetry/sdk/Metrics/Aggregation/LastValueAggregation.php new file mode 100644 index 000000000..aff04e315 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Aggregation/LastValueAggregation.php @@ -0,0 +1,81 @@ + + */ +final class LastValueAggregation implements AggregationInterface +{ + public function initialize(): LastValueSummary + { + return new LastValueSummary(null, 0); + } + + /** + * @param LastValueSummary $summary + */ + public function record($summary, $value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): void + { + if ($summary->value === null || $timestamp >= $summary->timestamp) { + $summary->value = $value; + $summary->timestamp = $timestamp; + } + } + + /** + * @param LastValueSummary $left + * @param LastValueSummary $right + */ + public function merge($left, $right): LastValueSummary + { + return $right->timestamp >= $left->timestamp ? $right : $left; + } + + /** + * @param LastValueSummary $left + * @param LastValueSummary $right + */ + public function diff($left, $right): LastValueSummary + { + return $right->timestamp >= $left->timestamp ? $right : $left; + } + + /** + * @param array $summaries + */ + public function toData( + array $attributes, + array $summaries, + array $exemplars, + int $startTimestamp, + int $timestamp, + $temporality + ): Data\Gauge { + $dataPoints = []; + foreach ($attributes as $key => $dataPointAttributes) { + if ($summaries[$key]->value === null) { + continue; + } + + $dataPoints[] = new Data\NumberDataPoint( + $summaries[$key]->value, + $dataPointAttributes, + $startTimestamp, + $timestamp, + $exemplars[$key] ?? [], + ); + } + + return new Data\Gauge( + $dataPoints, + ); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Aggregation/LastValueSummary.php b/vendor/open-telemetry/sdk/Metrics/Aggregation/LastValueSummary.php new file mode 100644 index 000000000..6cdb5ac9f --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Aggregation/LastValueSummary.php @@ -0,0 +1,22 @@ +value = $value; + $this->timestamp = $timestamp; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Aggregation/SumAggregation.php b/vendor/open-telemetry/sdk/Metrics/Aggregation/SumAggregation.php new file mode 100644 index 000000000..dc317ce73 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Aggregation/SumAggregation.php @@ -0,0 +1,91 @@ + + */ +final class SumAggregation implements AggregationInterface +{ + private bool $monotonic; + + public function __construct(bool $monotonic = false) + { + $this->monotonic = $monotonic; + } + + public function initialize(): SumSummary + { + return new SumSummary(0); + } + + /** + * @param SumSummary $summary + */ + public function record($summary, $value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): void + { + $summary->value += $value; + } + + /** + * @param SumSummary $left + * @param SumSummary $right + */ + public function merge($left, $right): SumSummary + { + $sum = $left->value + $right->value; + + return new SumSummary( + $sum, + ); + } + + /** + * @param SumSummary $left + * @param SumSummary $right + */ + public function diff($left, $right): SumSummary + { + $sum = -$left->value + $right->value; + + return new SumSummary( + $sum, + ); + } + + /** + * @param array $summaries + */ + public function toData( + array $attributes, + array $summaries, + array $exemplars, + int $startTimestamp, + int $timestamp, + $temporality + ): Data\Sum { + $dataPoints = []; + foreach ($attributes as $key => $dataPointAttributes) { + $dataPoints[] = new Data\NumberDataPoint( + $summaries[$key]->value, + $dataPointAttributes, + $startTimestamp, + $timestamp, + $exemplars[$key] ?? [], + ); + } + + return new Data\Sum( + $dataPoints, + $temporality, + $this->monotonic, + ); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Aggregation/SumSummary.php b/vendor/open-telemetry/sdk/Metrics/Aggregation/SumSummary.php new file mode 100644 index 000000000..9b257193c --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Aggregation/SumSummary.php @@ -0,0 +1,20 @@ +value = $value; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/AggregationInterface.php b/vendor/open-telemetry/sdk/Metrics/AggregationInterface.php new file mode 100644 index 000000000..0a85207e0 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/AggregationInterface.php @@ -0,0 +1,57 @@ + $attributes + * @psalm-param array $summaries + * @param array> $exemplars + * @param string|Temporality $temporality + */ + public function toData( + array $attributes, + array $summaries, + array $exemplars, + int $startTimestamp, + int $timestamp, + $temporality + ): DataInterface; +} diff --git a/vendor/open-telemetry/sdk/Metrics/AggregationTemporalitySelectorInterface.php b/vendor/open-telemetry/sdk/Metrics/AggregationTemporalitySelectorInterface.php new file mode 100644 index 000000000..f046d033d --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/AggregationTemporalitySelectorInterface.php @@ -0,0 +1,21 @@ +attributeKeys = $attributeKeys; + } + + public function process(AttributesInterface $attributes, ContextInterface $context): AttributesInterface + { + $filtered = []; + foreach ($this->attributeKeys as $key) { + $filtered[$key] = $attributes->get($key); + } + + return new Attributes($filtered, 0); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/AttributeProcessor/IdentityAttributeProcessor.php b/vendor/open-telemetry/sdk/Metrics/AttributeProcessor/IdentityAttributeProcessor.php new file mode 100644 index 000000000..f261563ea --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/AttributeProcessor/IdentityAttributeProcessor.php @@ -0,0 +1,20 @@ +writer = $writer; + $this->instrument = $instrument; + $this->referenceCounter = $referenceCounter; + + $this->referenceCounter->acquire(); + } + + public function __destruct() + { + $this->referenceCounter->release(); + } + + public function add($amount, iterable $attributes = [], $context = null): void + { + $this->writer->record($this->instrument, $amount, $attributes, $context); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Data/DataInterface.php b/vendor/open-telemetry/sdk/Metrics/Data/DataInterface.php new file mode 100644 index 000000000..7aa0c0e20 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Data/DataInterface.php @@ -0,0 +1,9 @@ +index = $index; + $this->value = $value; + $this->timestamp = $timestamp; + $this->attributes = $attributes; + $this->traceId = $traceId; + $this->spanId = $spanId; + } + + /** + * @param iterable $exemplars + * @return array> + */ + public static function groupByIndex(iterable $exemplars): array + { + $grouped = []; + foreach ($exemplars as $exemplar) { + $grouped[$exemplar->index][] = $exemplar; + } + + return $grouped; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Data/Gauge.php b/vendor/open-telemetry/sdk/Metrics/Data/Gauge.php new file mode 100644 index 000000000..00eb50939 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Data/Gauge.php @@ -0,0 +1,22 @@ + + * @readonly + */ + public iterable $dataPoints; + /** + * @param iterable $dataPoints + */ + public function __construct(iterable $dataPoints) + { + $this->dataPoints = $dataPoints; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Data/Histogram.php b/vendor/open-telemetry/sdk/Metrics/Data/Histogram.php new file mode 100644 index 000000000..782698026 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Data/Histogram.php @@ -0,0 +1,29 @@ + + * @readonly + */ + public iterable $dataPoints; + /** + * @var string|Temporality + * @readonly + */ + public $temporality; + /** + * @param iterable $dataPoints + * @param string|Temporality $temporality + */ + public function __construct(iterable $dataPoints, $temporality) + { + $this->dataPoints = $dataPoints; + $this->temporality = $temporality; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Data/HistogramDataPoint.php b/vendor/open-telemetry/sdk/Metrics/Data/HistogramDataPoint.php new file mode 100644 index 000000000..4c9df07b4 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Data/HistogramDataPoint.php @@ -0,0 +1,76 @@ + + * @readonly + */ + public array $explicitBounds; + /** + * @readonly + */ + public AttributesInterface $attributes; + /** + * @readonly + */ + public int $startTimestamp; + /** + * @readonly + */ + public int $timestamp; + /** + * @readonly + */ + public iterable $exemplars = []; + /** + * @param float|int $sum + * @param float|int $min + * @param float|int $max + * @param int[] $bucketCounts + * @param list $explicitBounds + */ + public function __construct(int $count, $sum, $min, $max, array $bucketCounts, array $explicitBounds, AttributesInterface $attributes, int $startTimestamp, int $timestamp, iterable $exemplars = []) + { + $this->count = $count; + $this->sum = $sum; + $this->min = $min; + $this->max = $max; + $this->bucketCounts = $bucketCounts; + $this->explicitBounds = $explicitBounds; + $this->attributes = $attributes; + $this->startTimestamp = $startTimestamp; + $this->timestamp = $timestamp; + $this->exemplars = $exemplars; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Data/Metric.php b/vendor/open-telemetry/sdk/Metrics/Data/Metric.php new file mode 100644 index 000000000..41fcb52dd --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Data/Metric.php @@ -0,0 +1,46 @@ +instrumentationScope = $instrumentationScope; + $this->resource = $resource; + $this->name = $name; + $this->description = $description; + $this->unit = $unit; + $this->data = $data; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Data/NumberDataPoint.php b/vendor/open-telemetry/sdk/Metrics/Data/NumberDataPoint.php new file mode 100644 index 000000000..1d00e783a --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Data/NumberDataPoint.php @@ -0,0 +1,43 @@ +value = $value; + $this->attributes = $attributes; + $this->startTimestamp = $startTimestamp; + $this->timestamp = $timestamp; + $this->exemplars = $exemplars; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Data/Sum.php b/vendor/open-telemetry/sdk/Metrics/Data/Sum.php new file mode 100644 index 000000000..77c4c1021 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Data/Sum.php @@ -0,0 +1,34 @@ + + * @readonly + */ + public iterable $dataPoints; + /** + * @var string|Temporality + * @readonly + */ + public $temporality; + /** + * @readonly + */ + public bool $monotonic; + /** + * @param iterable $dataPoints + * @param string|Temporality $temporality + */ + public function __construct(iterable $dataPoints, $temporality, bool $monotonic) + { + $this->dataPoints = $dataPoints; + $this->temporality = $temporality; + $this->monotonic = $monotonic; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Data/Temporality.php b/vendor/open-telemetry/sdk/Metrics/Data/Temporality.php new file mode 100644 index 000000000..b6642ebd0 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Data/Temporality.php @@ -0,0 +1,20 @@ + */ + private array $buckets; + + public function __construct(int $size = 0) + { + $this->buckets = array_fill(0, $size, null); + } + + /** + * @param int|string $index + * @param float|int $value + */ + public function store(int $bucket, $index, $value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): void + { + assert($bucket <= count($this->buckets)); + + $exemplar = $this->buckets[$bucket] ??= new BucketEntry(); + $exemplar->index = $index; + $exemplar->value = $value; + $exemplar->timestamp = $timestamp; + $exemplar->attributes = $attributes; + + if (($spanContext = Span::fromContext($context)->getContext())->isValid()) { + $exemplar->traceId = $spanContext->getTraceId(); + $exemplar->spanId = $spanContext->getSpanId(); + } else { + $exemplar->traceId = null; + $exemplar->spanId = null; + } + } + + /** + * @param array $dataPointAttributes + * @return array + */ + public function collect(array $dataPointAttributes): array + { + $exemplars = []; + foreach ($this->buckets as $index => &$exemplar) { + if (!$exemplar) { + continue; + } + + $exemplars[$index] = new Exemplar( + $exemplar->index, + $exemplar->value, + $exemplar->timestamp, + $this->filterExemplarAttributes( + $dataPointAttributes[$exemplar->index], + $exemplar->attributes, + ), + $exemplar->traceId, + $exemplar->spanId, + ); + $exemplar = null; + } + + return $exemplars; + } + + private function filterExemplarAttributes(AttributesInterface $dataPointAttributes, AttributesInterface $exemplarAttributes): AttributesInterface + { + $attributes = []; + foreach ($exemplarAttributes as $key => $value) { + if ($dataPointAttributes->get($key) === null) { + $attributes[$key] = $value; + } + } + + return new Attributes($attributes, $exemplarAttributes->getDroppedAttributesCount()); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Exemplar/ExemplarFilter/AllExemplarFilter.php b/vendor/open-telemetry/sdk/Metrics/Exemplar/ExemplarFilter/AllExemplarFilter.php new file mode 100644 index 000000000..b74e738aa --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Exemplar/ExemplarFilter/AllExemplarFilter.php @@ -0,0 +1,21 @@ +getContext()->isSampled(); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Exemplar/ExemplarFilterInterface.php b/vendor/open-telemetry/sdk/Metrics/Exemplar/ExemplarFilterInterface.php new file mode 100644 index 000000000..1d5dec7b8 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Exemplar/ExemplarFilterInterface.php @@ -0,0 +1,20 @@ + $dataPointAttributes + * @return array + */ + public function collect(array $dataPointAttributes): array; +} diff --git a/vendor/open-telemetry/sdk/Metrics/Exemplar/FilteredReservoir.php b/vendor/open-telemetry/sdk/Metrics/Exemplar/FilteredReservoir.php new file mode 100644 index 000000000..0e4f24357 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Exemplar/FilteredReservoir.php @@ -0,0 +1,36 @@ +reservoir = $reservoir; + $this->filter = $filter; + } + + public function offer($index, $value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): void + { + if ($this->filter->accepts($value, $attributes, $context, $timestamp)) { + $this->reservoir->offer($index, $value, $attributes, $context, $timestamp); + } + } + + public function collect(array $dataPointAttributes): array + { + return $this->reservoir->collect($dataPointAttributes); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Exemplar/FixedSizeReservoir.php b/vendor/open-telemetry/sdk/Metrics/Exemplar/FixedSizeReservoir.php new file mode 100644 index 000000000..479292a4c --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Exemplar/FixedSizeReservoir.php @@ -0,0 +1,38 @@ +storage = new BucketStorage($size); + $this->size = $size; + } + + public function offer($index, $value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): void + { + $bucket = random_int(0, $this->measurements); + $this->measurements++; + if ($bucket < $this->size) { + $this->storage->store($bucket, $index, $value, $attributes, $context, $timestamp); + } + } + + public function collect(array $dataPointAttributes): array + { + $this->measurements = 0; + + return $this->storage->collect($dataPointAttributes); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Exemplar/HistogramBucketReservoir.php b/vendor/open-telemetry/sdk/Metrics/Exemplar/HistogramBucketReservoir.php new file mode 100644 index 000000000..b56a1b2be --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Exemplar/HistogramBucketReservoir.php @@ -0,0 +1,40 @@ + + */ + private array $boundaries; + + /** + * @param list $boundaries + */ + public function __construct(array $boundaries) + { + $this->storage = new BucketStorage(count($boundaries) + 1); + $this->boundaries = $boundaries; + } + + public function offer($index, $value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): void + { + $boundariesCount = count($this->boundaries); + for ($i = 0; $i < $boundariesCount && $this->boundaries[$i] < $value; $i++) { + } + $this->storage->store($i, $index, $value, $attributes, $context, $timestamp); + } + + public function collect(array $dataPointAttributes): array + { + return $this->storage->collect($dataPointAttributes); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Exemplar/NoopReservoir.php b/vendor/open-telemetry/sdk/Metrics/Exemplar/NoopReservoir.php new file mode 100644 index 000000000..010aeff20 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Exemplar/NoopReservoir.php @@ -0,0 +1,21 @@ +writer = $writer; + $this->instrument = $instrument; + $this->referenceCounter = $referenceCounter; + + $this->referenceCounter->acquire(); + } + + public function __destruct() + { + $this->referenceCounter->release(); + } + + public function record($amount, iterable $attributes = [], $context = null): void + { + $this->writer->record($this->instrument, $amount, $attributes, $context); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Instrument.php b/vendor/open-telemetry/sdk/Metrics/Instrument.php new file mode 100644 index 000000000..3543604c0 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Instrument.php @@ -0,0 +1,36 @@ +type = $type; + $this->name = $name; + $this->unit = $unit; + $this->description = $description; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/InstrumentType.php b/vendor/open-telemetry/sdk/Metrics/InstrumentType.php new file mode 100644 index 000000000..ae603b2fe --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/InstrumentType.php @@ -0,0 +1,25 @@ + */ + private iterable $metricRegistries; + private ViewRegistryInterface $viewRegistry; + private ?ExemplarFilterInterface $exemplarFilter; + private MeterInstruments $instruments; + private InstrumentationScopeInterface $instrumentationScope; + + private MetricRegistryInterface $registry; + private MetricWriterInterface $writer; + + private ?string $instrumentationScopeId = null; + + /** + * @param iterable $metricRegistries + */ + public function __construct( + MetricFactoryInterface $metricFactory, + ResourceInfo $resource, + ClockInterface $clock, + StalenessHandlerFactoryInterface $stalenessHandlerFactory, + iterable $metricRegistries, + ViewRegistryInterface $viewRegistry, + ?ExemplarFilterInterface $exemplarFilter, + MeterInstruments $instruments, + InstrumentationScopeInterface $instrumentationScope, + MetricRegistryInterface $registry, + MetricWriterInterface $writer + ) { + $this->metricFactory = $metricFactory; + $this->resource = $resource; + $this->clock = $clock; + $this->stalenessHandlerFactory = $stalenessHandlerFactory; + $this->metricRegistries = $metricRegistries; + $this->viewRegistry = $viewRegistry; + $this->exemplarFilter = $exemplarFilter; + $this->instruments = $instruments; + $this->instrumentationScope = $instrumentationScope; + $this->registry = $registry; + $this->writer = $writer; + } + + public function createCounter(string $name, ?string $unit = null, ?string $description = null): CounterInterface + { + [$instrument, $referenceCounter] = $this->createSynchronousWriter( + InstrumentType::COUNTER, + $name, + $unit, + $description, + ); + + return new Counter($this->writer, $instrument, $referenceCounter); + } + + public function createObservableCounter(string $name, ?string $unit = null, ?string $description = null, callable ...$callbacks): ObservableCounterInterface + { + [$instrument, $referenceCounter, $destructors] = $this->createAsynchronousObserver( + InstrumentType::ASYNCHRONOUS_COUNTER, + $name, + $unit, + $description, + ); + + foreach ($callbacks as $callback) { + $this->writer->registerCallback(closure($callback), $instrument); + $referenceCounter->acquire(true); + } + + return new ObservableCounter($this->writer, $instrument, $referenceCounter, $destructors); + } + + public function createHistogram(string $name, ?string $unit = null, ?string $description = null): HistogramInterface + { + [$instrument, $referenceCounter] = $this->createSynchronousWriter( + InstrumentType::HISTOGRAM, + $name, + $unit, + $description, + ); + + return new Histogram($this->writer, $instrument, $referenceCounter); + } + + public function createObservableGauge(string $name, ?string $unit = null, ?string $description = null, callable ...$callbacks): ObservableGaugeInterface + { + [$instrument, $referenceCounter, $destructors] = $this->createAsynchronousObserver( + InstrumentType::ASYNCHRONOUS_GAUGE, + $name, + $unit, + $description, + ); + + foreach ($callbacks as $callback) { + $this->writer->registerCallback(closure($callback), $instrument); + $referenceCounter->acquire(true); + } + + return new ObservableGauge($this->writer, $instrument, $referenceCounter, $destructors); + } + + public function createUpDownCounter(string $name, ?string $unit = null, ?string $description = null): UpDownCounterInterface + { + [$instrument, $referenceCounter] = $this->createSynchronousWriter( + InstrumentType::UP_DOWN_COUNTER, + $name, + $unit, + $description, + ); + + return new UpDownCounter($this->writer, $instrument, $referenceCounter); + } + + public function createObservableUpDownCounter(string $name, ?string $unit = null, ?string $description = null, callable ...$callbacks): ObservableUpDownCounterInterface + { + [$instrument, $referenceCounter, $destructors] = $this->createAsynchronousObserver( + InstrumentType::ASYNCHRONOUS_UP_DOWN_COUNTER, + $name, + $unit, + $description, + ); + + foreach ($callbacks as $callback) { + $this->writer->registerCallback(closure($callback), $instrument); + $referenceCounter->acquire(true); + } + + return new ObservableUpDownCounter($this->writer, $instrument, $referenceCounter, $destructors); + } + + /** + * @param string|InstrumentType $instrumentType + * @return array{Instrument, ReferenceCounterInterface} + */ + private function createSynchronousWriter($instrumentType, string $name, ?string $unit, ?string $description): array + { + $instrument = new Instrument($instrumentType, $name, $unit, $description); + + $instrumentationScopeId = $this->instrumentationScopeId($this->instrumentationScope); + $instrumentId = $this->instrumentId($instrument); + + $instruments = $this->instruments; + if ($writer = $instruments->writers[$instrumentationScopeId][$instrumentId] ?? null) { + return $writer; + } + + $stalenessHandler = $this->stalenessHandlerFactory->create(); + $instruments->startTimestamp ??= $this->clock->now(); + $streamIds = $this->metricFactory->createSynchronousWriter( + $this->registry, + $this->resource, + $this->instrumentationScope, + $instrument, + $instruments->startTimestamp, + $this->viewRegistrationRequests($instrument, $stalenessHandler), + $this->exemplarFilter, + ); + + $registry = $this->registry; + $stalenessHandler->onStale(static function () use ($instruments, $instrumentationScopeId, $instrumentId, $registry, $streamIds): void { + unset($instruments->writers[$instrumentationScopeId][$instrumentId]); + if (!$instruments->writers[$instrumentationScopeId]) { + unset($instruments->writers[$instrumentationScopeId]); + } + foreach ($streamIds as $streamId) { + $registry->unregisterStream($streamId); + } + + $instruments->startTimestamp = null; + }); + + return $instruments->writers[$instrumentationScopeId][$instrumentId] = [ + $instrument, + $stalenessHandler, + ]; + } + + /** + * @param string|InstrumentType $instrumentType + * @return array{Instrument, ReferenceCounterInterface, ArrayAccess} + */ + private function createAsynchronousObserver($instrumentType, string $name, ?string $unit, ?string $description): array + { + $instrument = new Instrument($instrumentType, $name, $unit, $description); + + $instrumentationScopeId = $this->instrumentationScopeId($this->instrumentationScope); + $instrumentId = $this->instrumentId($instrument); + + $instruments = $this->instruments; + /** @phan-suppress-next-line PhanDeprecatedProperty */ + $instruments->staleObservers = []; + if ($observer = $instruments->observers[$instrumentationScopeId][$instrumentId] ?? null) { + return $observer; + } + + $stalenessHandler = $this->stalenessHandlerFactory->create(); + $instruments->startTimestamp ??= $this->clock->now(); + $streamIds = $this->metricFactory->createAsynchronousObserver( + $this->registry, + $this->resource, + $this->instrumentationScope, + $instrument, + $instruments->startTimestamp, + $this->viewRegistrationRequests($instrument, $stalenessHandler), + ); + + $registry = $this->registry; + $stalenessHandler->onStale(static function () use ($instruments, $instrumentationScopeId, $instrumentId, $registry, $streamIds): void { + if (PHP_VERSION_ID < 80000) { + /** @phan-suppress-next-line PhanDeprecatedProperty */ + $instruments->staleObservers[] = $instruments->observers[$instrumentationScopeId][$instrumentId][2]; + } + + unset($instruments->observers[$instrumentationScopeId][$instrumentId]); + if (!$instruments->observers[$instrumentationScopeId]) { + unset($instruments->observers[$instrumentationScopeId]); + } + foreach ($streamIds as $streamId) { + $registry->unregisterStream($streamId); + } + + $instruments->startTimestamp = null; + }); + + /** @var ArrayAccess $destructors */ + $destructors = WeakMap::create(); + + return $instruments->observers[$instrumentationScopeId][$instrumentId] = [ + $instrument, + $stalenessHandler, + $destructors, + ]; + } + + /** + * @return iterable + */ + private function viewRegistrationRequests(Instrument $instrument, StalenessHandlerInterface $stalenessHandler): iterable + { + $views = $this->viewRegistry->find($instrument, $this->instrumentationScope) ?? [ + new ViewProjection( + $instrument->name, + $instrument->unit, + $instrument->description, + null, + null, + ), + ]; + + $compositeRegistration = new MultiRegistryRegistration($this->metricRegistries, $stalenessHandler); + foreach ($views as $view) { + if ($view->aggregation !== null) { + yield [$view, $compositeRegistration]; + } else { + foreach ($this->metricRegistries as $metricRegistry) { + yield [ + new ViewProjection( + $view->name, + $view->unit, + $view->description, + $view->attributeKeys, + $metricRegistry->defaultAggregation($instrument->type), + ), + new RegistryRegistration($metricRegistry, $stalenessHandler), + ]; + } + } + } + } + + private function instrumentationScopeId(InstrumentationScopeInterface $instrumentationScope): string + { + return $this->instrumentationScopeId ??= serialize($instrumentationScope); + } + + private function instrumentId(Instrument $instrument): string + { + return serialize($instrument); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/MeterInstruments.php b/vendor/open-telemetry/sdk/Metrics/MeterInstruments.php new file mode 100644 index 000000000..c331cb608 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/MeterInstruments.php @@ -0,0 +1,29 @@ +}>> + */ + public array $observers = []; + /** + * @var array> + */ + public array $writers = []; + + /** + * @var list> + * @deprecated + */ + public array $staleObservers = []; +} diff --git a/vendor/open-telemetry/sdk/Metrics/MeterProvider.php b/vendor/open-telemetry/sdk/Metrics/MeterProvider.php new file mode 100644 index 000000000..36c17cf81 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/MeterProvider.php @@ -0,0 +1,130 @@ + $metricReaders + */ + public function __construct( + ?ContextStorageInterface $contextStorage, + ResourceInfo $resource, + ClockInterface $clock, + AttributesFactoryInterface $attributesFactory, + InstrumentationScopeFactoryInterface $instrumentationScopeFactory, + iterable $metricReaders, + ViewRegistryInterface $viewRegistry, + ?ExemplarFilterInterface $exemplarFilter, + StalenessHandlerFactoryInterface $stalenessHandlerFactory, + MetricFactoryInterface $metricFactory = null + ) { + $this->metricFactory = $metricFactory ?? new StreamFactory(); + $this->resource = $resource; + $this->clock = $clock; + $this->instrumentationScopeFactory = $instrumentationScopeFactory; + $this->metricReaders = $metricReaders; + $this->viewRegistry = $viewRegistry; + $this->exemplarFilter = $exemplarFilter; + $this->stalenessHandlerFactory = $stalenessHandlerFactory; + $this->instruments = new MeterInstruments(); + + $registry = new MetricRegistry($contextStorage, $attributesFactory, $clock); + $this->registry = $registry; + $this->writer = $registry; + } + + public function getMeter( + string $name, + ?string $version = null, + ?string $schemaUrl = null, + iterable $attributes = [] + ): MeterInterface { + if ($this->closed || Sdk::isDisabled()) { //@todo create meter provider from factory, and move Sdk::isDisabled() there + return new NoopMeter(); + } + + return new Meter( + $this->metricFactory, + $this->resource, + $this->clock, + $this->stalenessHandlerFactory, + $this->metricReaders, + $this->viewRegistry, + $this->exemplarFilter, + $this->instruments, + $this->instrumentationScopeFactory->create($name, $version, $schemaUrl, $attributes), + $this->registry, + $this->writer, + ); + } + + public function shutdown(): bool + { + if ($this->closed) { + return false; + } + + $this->closed = true; + + $success = true; + foreach ($this->metricReaders as $metricReader) { + if (!$metricReader->shutdown()) { + $success = false; + } + } + + return $success; + } + + public function forceFlush(): bool + { + if ($this->closed) { + return false; + } + + $success = true; + foreach ($this->metricReaders as $metricReader) { + if (!$metricReader->forceFlush()) { + $success = false; + } + } + + return $success; + } + + public static function builder(): MeterProviderBuilder + { + return new MeterProviderBuilder(); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/MeterProviderBuilder.php b/vendor/open-telemetry/sdk/Metrics/MeterProviderBuilder.php new file mode 100644 index 000000000..17f0be895 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/MeterProviderBuilder.php @@ -0,0 +1,62 @@ + + private array $metricReaders = []; + private ?ResourceInfo $resource = null; + private ?ExemplarFilterInterface $exemplarFilter = null; + + public function setResource(ResourceInfo $resource): self + { + $this->resource = $resource; + + return $this; + } + + public function setExemplarFilter(ExemplarFilterInterface $exemplarFilter): self + { + $this->exemplarFilter = $exemplarFilter; + + return $this; + } + + public function addReader(MetricReaderInterface $reader): self + { + $this->metricReaders[] = $reader; + + return $this; + } + + /** + * @psalm-suppress PossiblyInvalidArgument + */ + public function build(): MeterProviderInterface + { + return new MeterProvider( + null, + $this->resource ?? ResourceInfoFactory::emptyResource(), + ClockFactory::getDefault(), + Attributes::factory(), + new InstrumentationScopeFactory(Attributes::factory()), + $this->metricReaders, + new CriteriaViewRegistry(), + $this->exemplarFilter ?? new WithSampledTraceExemplarFilter(), + new NoopStalenessHandlerFactory(), + ); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/MeterProviderFactory.php b/vendor/open-telemetry/sdk/Metrics/MeterProviderFactory.php new file mode 100644 index 000000000..5f7f9988d --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/MeterProviderFactory.php @@ -0,0 +1,78 @@ +create(); + } catch (\Throwable $t) { + self::logWarning(sprintf('Unable to create %s meter provider: %s', $exporterName, $t->getMessage())); + $exporter = new NoopMetricExporter(); + } + + // @todo "The exporter MUST be paired with a periodic exporting MetricReader" + $reader = new ExportingReader($exporter); + $resource = ResourceInfoFactory::defaultResource(); + $exemplarFilter = $this->createExemplarFilter(Configuration::getEnum(Variables::OTEL_METRICS_EXEMPLAR_FILTER)); + + return MeterProvider::builder() + ->setResource($resource) + ->addReader($reader) + ->setExemplarFilter($exemplarFilter) + ->build(); + } + + private function createExemplarFilter(string $name): ExemplarFilterInterface + { + switch ($name) { + case KnownValues::VALUE_WITH_SAMPLED_TRACE: + return new WithSampledTraceExemplarFilter(); + case KnownValues::VALUE_ALL: + return new AllExemplarFilter(); + case KnownValues::VALUE_NONE: + return new NoneExemplarFilter(); + default: + self::logWarning('Unknown exemplar filter: ' . $name); + + return new NoneExemplarFilter(); + } + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/MeterProviderInterface.php b/vendor/open-telemetry/sdk/Metrics/MeterProviderInterface.php new file mode 100644 index 000000000..fcb951106 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/MeterProviderInterface.php @@ -0,0 +1,12 @@ +temporality = $temporality; + } + /** + * @inheritDoc + */ + public function temporality(MetricMetadataInterface $metric) + { + return $this->temporality ?? $metric->temporality(); + } + + /** + * @inheritDoc + */ + public function export(iterable $batch): bool + { + $resource = null; + $scope = null; + foreach ($batch as $metric) { + /** @var Metric $metric */ + if (!$resource) { + $resource = $this->convertResource($metric->resource); + } + if (!$scope) { + $scope = $this->convertInstrumentationScope($metric->instrumentationScope); + $scope['metrics'] = []; + } + $scope['metrics'][] = $this->convertMetric($metric); + } + $output = [ + 'resource' => $resource, + 'scope' => $scope, + ]; + echo json_encode($output, JSON_PRETTY_PRINT) . PHP_EOL; + + return true; + } + + public function shutdown(): bool + { + return true; + } + + public function forceFlush(): bool + { + return true; + } + + private function convertMetric(Metric $metric): array + { + return [ + 'name' => $metric->name, + 'description' => $metric->description, + 'unit' => $metric->unit, + 'data' => $metric->data, + ]; + } + + private function convertResource(ResourceInfo $resource): array + { + return [ + 'attributes' => $resource->getAttributes()->toArray(), + 'dropped_attributes_count' => $resource->getAttributes()->getDroppedAttributesCount(), + ]; + } + private function convertInstrumentationScope(InstrumentationScopeInterface $scope): array + { + return [ + 'name' => $scope->getName(), + 'version' => $scope->getVersion(), + 'attributes' => $scope->getAttributes()->toArray(), + 'dropped_attributes_count' => $scope->getAttributes()->getDroppedAttributesCount(), + 'schema_url' => $scope->getSchemaUrl(), + ]; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/MetricExporter/ConsoleMetricExporterFactory.php b/vendor/open-telemetry/sdk/Metrics/MetricExporter/ConsoleMetricExporterFactory.php new file mode 100644 index 000000000..19088738d --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/MetricExporter/ConsoleMetricExporterFactory.php @@ -0,0 +1,16 @@ + + */ + private array $metrics = []; + /** + * @var string|Temporality|null + */ + private $temporality; + + private bool $closed = false; + + /** + * @param string|Temporality|null $temporality + */ + public function __construct($temporality = null) + { + $this->temporality = $temporality; + } + + public function temporality(MetricMetadataInterface $metric) + { + return $this->temporality ?? $metric->temporality(); + } + + /** + * @return list + */ + public function collect(bool $reset = false): array + { + $metrics = $this->metrics; + if ($reset) { + $this->metrics = []; + } + + return $metrics; + } + + public function export(iterable $batch): bool + { + if ($this->closed) { + return false; + } + + /** @psalm-suppress InvalidPropertyAssignmentValue */ + array_push($this->metrics, ...$batch); + + return true; + } + + public function shutdown(): bool + { + if ($this->closed) { + return false; + } + + $this->closed = true; + + return true; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/MetricExporter/InMemoryExporterFactory.php b/vendor/open-telemetry/sdk/Metrics/MetricExporter/InMemoryExporterFactory.php new file mode 100644 index 000000000..c72c7b169 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/MetricExporter/InMemoryExporterFactory.php @@ -0,0 +1,16 @@ + $batch + */ + public function export(iterable $batch): bool; + + public function shutdown(): bool; +} diff --git a/vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamFactory.php b/vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamFactory.php new file mode 100644 index 000000000..2c3af4c06 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamFactory.php @@ -0,0 +1,187 @@ +aggregation === null) { + continue; + } + + $dedupId = $this->streamId($view->aggregation, $view->attributeKeys); + if (($streamId = $dedup[$dedupId] ?? null) === null) { + $stream = new AsynchronousMetricStream($view->aggregation, $timestamp); + $streamId = $registry->registerAsynchronousStream($instrument, $stream, new MetricAggregatorFactory( + $this->attributeProcessor($view->attributeKeys), + $view->aggregation, + )); + + $streams[$streamId] = $stream; + $dedup[$dedupId] = $streamId; + } + + $this->registerSource( + $view, + $instrument, + $instrumentationScope, + $resource, + $streams[$streamId], + $registry, + $registration, + $streamId, + ); + } + + return array_keys($streams); + } + + public function createSynchronousWriter( + MetricRegistryInterface $registry, + ResourceInfo $resource, + InstrumentationScopeInterface $instrumentationScope, + Instrument $instrument, + int $timestamp, + iterable $views, + ?ExemplarFilterInterface $exemplarFilter = null + ): array { + $streams = []; + $dedup = []; + foreach ($views as [$view, $registration]) { + if ($view->aggregation === null) { + continue; + } + + $dedupId = $this->streamId($view->aggregation, $view->attributeKeys); + if (($streamId = $dedup[$dedupId] ?? null) === null) { + $stream = new SynchronousMetricStream($view->aggregation, $timestamp); + $streamId = $registry->registerSynchronousStream($instrument, $stream, new MetricAggregator( + $this->attributeProcessor($view->attributeKeys), + $view->aggregation, + $this->createExemplarReservoir($view->aggregation, $exemplarFilter), + )); + + $streams[$streamId] = $stream; + $dedup[$dedupId] = $streamId; + } + + $this->registerSource( + $view, + $instrument, + $instrumentationScope, + $resource, + $streams[$streamId], + $registry, + $registration, + $streamId, + ); + } + + return array_keys($streams); + } + + private function attributeProcessor( + ?array $attributeKeys + ): ?AttributeProcessorInterface { + return $attributeKeys !== null + ? new FilteredAttributeProcessor($attributeKeys) + : null; + } + + private function createExemplarReservoir( + AggregationInterface $aggregation, + ?ExemplarFilterInterface $exemplarFilter + ): ?ExemplarReservoirInterface { + if (!$exemplarFilter) { + return null; + } + + if ($aggregation instanceof ExplicitBucketHistogramAggregation && $aggregation->boundaries) { + $exemplarReservoir = new HistogramBucketReservoir($aggregation->boundaries); + } else { + $exemplarReservoir = new FixedSizeReservoir(); + } + + return new FilteredReservoir($exemplarReservoir, $exemplarFilter); + } + + private function registerSource( + ViewProjection $view, + Instrument $instrument, + InstrumentationScopeInterface $instrumentationScope, + ResourceInfo $resource, + MetricStreamInterface $stream, + MetricCollectorInterface $metricCollector, + MetricRegistrationInterface $metricRegistration, + int $streamId + ): void { + $provider = new StreamMetricSourceProvider( + $view, + $instrument, + $instrumentationScope, + $resource, + $stream, + $metricCollector, + $streamId, + ); + + $metricRegistration->register($provider, $provider); + } + + private function streamId(AggregationInterface $aggregation, ?array $attributeKeys): string + { + return $this->trySerialize($aggregation) . serialize($attributeKeys); + } + + private function trySerialize(object $object) + { + try { + return serialize($object); + } catch (Throwable $e) { + } + + return spl_object_id($object); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamMetricSource.php b/vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamMetricSource.php new file mode 100644 index 000000000..4939a5341 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamMetricSource.php @@ -0,0 +1,44 @@ +provider = $provider; + $this->reader = $reader; + } + + public function collectionTimestamp(): int + { + return $this->provider->stream->timestamp(); + } + + public function collect(): Metric + { + return new Metric( + $this->provider->instrumentationLibrary, + $this->provider->resource, + $this->provider->view->name, + $this->provider->view->unit, + $this->provider->view->description, + $this->provider->stream->collect($this->reader), + ); + } + + public function __destruct() + { + $this->provider->stream->unregister($this->reader); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamMetricSourceProvider.php b/vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamMetricSourceProvider.php new file mode 100644 index 000000000..657c3ce62 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/MetricFactory/StreamMetricSourceProvider.php @@ -0,0 +1,98 @@ +view = $view; + $this->instrument = $instrument; + $this->instrumentationLibrary = $instrumentationLibrary; + $this->resource = $resource; + $this->stream = $stream; + $this->metricCollector = $metricCollector; + $this->streamId = $streamId; + } + + public function create($temporality): MetricSourceInterface + { + return new StreamMetricSource($this, $this->stream->register($temporality)); + } + + public function instrumentType() + { + return $this->instrument->type; + } + + public function name(): string + { + return $this->view->name; + } + + public function unit(): ?string + { + return $this->view->unit; + } + + public function description(): ?string + { + return $this->view->description; + } + + public function temporality() + { + return $this->stream->temporality(); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/MetricFactoryInterface.php b/vendor/open-telemetry/sdk/Metrics/MetricFactoryInterface.php new file mode 100644 index 000000000..a1e228eef --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/MetricFactoryInterface.php @@ -0,0 +1,41 @@ + $views + */ + public function createAsynchronousObserver( + MetricRegistryInterface $registry, + ResourceInfo $resource, + InstrumentationScopeInterface $instrumentationScope, + Instrument $instrument, + int $timestamp, + iterable $views + ): array; + + /** + * @param iterable $views + */ + public function createSynchronousWriter( + MetricRegistryInterface $registry, + ResourceInfo $resource, + InstrumentationScopeInterface $instrumentationScope, + Instrument $instrument, + int $timestamp, + iterable $views, + ?ExemplarFilterInterface $exemplarFilter = null + ): array; +} diff --git a/vendor/open-telemetry/sdk/Metrics/MetricMetadataInterface.php b/vendor/open-telemetry/sdk/Metrics/MetricMetadataInterface.php new file mode 100644 index 000000000..aa1a02d60 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/MetricMetadataInterface.php @@ -0,0 +1,28 @@ + */ + private array $sources = []; + + /** @var array */ + private array $registries = []; + /** @var array> */ + private array $streamIds = []; + + private bool $closed = false; + + public function __construct(MetricExporterInterface $exporter) + { + $this->exporter = $exporter; + } + + public function defaultAggregation($instrumentType): ?AggregationInterface + { + if ($this->exporter instanceof DefaultAggregationProviderInterface) { + return $this->exporter->defaultAggregation($instrumentType); + } + + return $this->_defaultAggregation($instrumentType); + } + + public function add(MetricSourceProviderInterface $provider, MetricMetadataInterface $metadata, StalenessHandlerInterface $stalenessHandler): void + { + if ($this->closed) { + return; + } + if (!$this->exporter instanceof AggregationTemporalitySelectorInterface) { + return; + } + if (!$temporality = $this->exporter->temporality($metadata)) { + return; + } + + $source = $provider->create($temporality); + $sourceId = spl_object_id($source); + + $this->sources[$sourceId] = $source; + $stalenessHandler->onStale(function () use ($sourceId): void { + unset($this->sources[$sourceId]); + }); + + if (!$provider instanceof StreamMetricSourceProvider) { + return; + } + + $streamId = $provider->streamId; + $registry = $provider->metricCollector; + $registryId = spl_object_id($registry); + + $this->registries[$registryId] = $registry; + $this->streamIds[$registryId][$streamId] ??= 0; + $this->streamIds[$registryId][$streamId]++; + + $stalenessHandler->onStale(function () use ($streamId, $registryId): void { + if (!--$this->streamIds[$registryId][$streamId]) { + unset($this->streamIds[$registryId][$streamId]); + if (!$this->streamIds[$registryId]) { + unset( + $this->registries[$registryId], + $this->streamIds[$registryId], + ); + } + } + }); + } + + private function doCollect(): bool + { + foreach ($this->registries as $registryId => $registry) { + $streamIds = $this->streamIds[$registryId] ?? []; + $registry->collectAndPush(array_keys($streamIds)); + } + + $metrics = []; + foreach ($this->sources as $source) { + $metrics[] = $source->collect(); + } + + if ($metrics === []) { + return true; + } + + return $this->exporter->export($metrics); + } + + public function collect(): bool + { + if ($this->closed) { + return false; + } + + return $this->doCollect(); + } + + public function shutdown(): bool + { + if ($this->closed) { + return false; + } + + $this->closed = true; + + $collect = $this->doCollect(); + $shutdown = $this->exporter->shutdown(); + + $this->sources = []; + + return $collect && $shutdown; + } + + public function forceFlush(): bool + { + if ($this->closed) { + return false; + } + if ($this->exporter instanceof PushMetricExporterInterface) { + $collect = $this->doCollect(); + $forceFlush = $this->exporter->forceFlush(); + + return $collect && $forceFlush; + } + + return true; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/MetricReaderInterface.php b/vendor/open-telemetry/sdk/Metrics/MetricReaderInterface.php new file mode 100644 index 000000000..f5900eef5 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/MetricReaderInterface.php @@ -0,0 +1,14 @@ + $registries + */ + public function __construct(iterable $registries, StalenessHandlerInterface $stalenessHandler) + { + $this->registries = $registries; + $this->stalenessHandler = $stalenessHandler; + } + + public function register(MetricSourceProviderInterface $provider, MetricMetadataInterface $metadata): void + { + foreach ($this->registries as $registry) { + $registry->add($provider, $metadata, $this->stalenessHandler); + } + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/MetricRegistration/RegistryRegistration.php b/vendor/open-telemetry/sdk/Metrics/MetricRegistration/RegistryRegistration.php new file mode 100644 index 000000000..3c1108902 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/MetricRegistration/RegistryRegistration.php @@ -0,0 +1,31 @@ +registry = $registry; + $this->stalenessHandler = $stalenessHandler; + } + + public function register(MetricSourceProviderInterface $provider, MetricMetadataInterface $metadata): void + { + $this->registry->add($provider, $metadata, $this->stalenessHandler); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/MetricRegistrationInterface.php b/vendor/open-telemetry/sdk/Metrics/MetricRegistrationInterface.php new file mode 100644 index 000000000..b0cc2484e --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/MetricRegistrationInterface.php @@ -0,0 +1,13 @@ + */ + private array $streams = []; + /** @var array */ + private array $synchronousAggregators = []; + /** @var array */ + private array $asynchronousAggregatorFactories = []; + + /** @var array> */ + private array $instrumentToStreams = []; + /** @var array */ + private array $streamToInstrument = []; + /** @var array> */ + private array $instrumentToCallbacks = []; + /** @var array */ + private array $asynchronousCallbacks = []; + /** @var array> */ + private array $asynchronousCallbackArguments = []; + + public function __construct( + ?ContextStorageInterface $contextStorage, + AttributesFactoryInterface $attributesFactory, + ClockInterface $clock + ) { + $this->contextStorage = $contextStorage; + $this->attributesFactory = $attributesFactory; + $this->clock = $clock; + } + + public function registerSynchronousStream(Instrument $instrument, MetricStreamInterface $stream, MetricAggregatorInterface $aggregator): int + { + $this->streams[] = $stream; + $streamId = array_key_last($this->streams); + $instrumentId = spl_object_id($instrument); + + $this->synchronousAggregators[$streamId] = $aggregator; + $this->instrumentToStreams[$instrumentId][$streamId] = $streamId; + $this->streamToInstrument[$streamId] = $instrumentId; + + return $streamId; + } + + public function registerAsynchronousStream(Instrument $instrument, MetricStreamInterface $stream, MetricAggregatorFactoryInterface $aggregatorFactory): int + { + $this->streams[] = $stream; + $streamId = array_key_last($this->streams); + $instrumentId = spl_object_id($instrument); + + $this->asynchronousAggregatorFactories[$streamId] = $aggregatorFactory; + $this->instrumentToStreams[$instrumentId][$streamId] = $streamId; + $this->streamToInstrument[$streamId] = $instrumentId; + + return $streamId; + } + + public function unregisterStream(int $streamId): void + { + $instrumentId = $this->streamToInstrument[$streamId]; + unset( + $this->streams[$streamId], + $this->synchronousAggregators[$streamId], + $this->asynchronousAggregatorFactories[$streamId], + $this->instrumentToStreams[$instrumentId][$streamId], + $this->streamToInstrument[$streamId], + ); + if (!$this->instrumentToStreams[$instrumentId]) { + unset($this->instrumentToStreams[$instrumentId]); + } + } + + public function record(Instrument $instrument, $value, iterable $attributes = [], $context = null): void + { + $context = Context::resolve($context, $this->contextStorage); + $attributes = $this->attributesFactory->builder($attributes)->build(); + $timestamp = $this->clock->now(); + $instrumentId = spl_object_id($instrument); + foreach ($this->instrumentToStreams[$instrumentId] ?? [] as $streamId) { + if ($aggregator = $this->synchronousAggregators[$streamId] ?? null) { + $aggregator->record($value, $attributes, $context, $timestamp); + } + } + } + + public function registerCallback(Closure $callback, Instrument $instrument, Instrument ...$instruments): int + { + $callbackId = array_key_last($this->asynchronousCallbacks) + 1; + $this->asynchronousCallbacks[$callbackId] = $callback; + + $instrumentId = spl_object_id($instrument); + $this->asynchronousCallbackArguments[$callbackId] = [$instrumentId]; + $this->instrumentToCallbacks[$instrumentId][$callbackId] = $callbackId; + foreach ($instruments as $instrument) { + $instrumentId = spl_object_id($instrument); + $this->asynchronousCallbackArguments[$callbackId][] = $instrumentId; + $this->instrumentToCallbacks[$instrumentId][$callbackId] = $callbackId; + } + + return $callbackId; + } + + public function unregisterCallback(int $callbackId): void + { + $instrumentIds = $this->asynchronousCallbackArguments[$callbackId]; + unset( + $this->asynchronousCallbacks[$callbackId], + $this->asynchronousCallbackArguments[$callbackId], + ); + foreach ($instrumentIds as $instrumentId) { + unset($this->instrumentToCallbacks[$instrumentId][$callbackId]); + if (!$this->instrumentToCallbacks[$instrumentId]) { + unset($this->instrumentToCallbacks[$instrumentId]); + } + } + } + + public function collectAndPush(iterable $streamIds): void + { + $timestamp = $this->clock->now(); + $aggregators = []; + $observers = []; + $callbackIds = []; + foreach ($streamIds as $streamId) { + if (!$aggregator = $this->synchronousAggregators[$streamId] ?? null) { + $aggregator = $this->asynchronousAggregatorFactories[$streamId]->create(); + + $instrumentId = $this->streamToInstrument[$streamId]; + $observers[$instrumentId] ??= new MultiObserver($this->attributesFactory, $timestamp); + $observers[$instrumentId]->writers[] = $aggregator; + foreach ($this->instrumentToCallbacks[$instrumentId] ?? [] as $callbackId) { + $callbackIds[$callbackId] = $callbackId; + } + } + + $aggregators[$streamId] = $aggregator; + } + + $noopObserver = new NoopObserver(); + $callbacks = []; + foreach ($callbackIds as $callbackId) { + $args = []; + foreach ($this->asynchronousCallbackArguments[$callbackId] as $instrumentId) { + $args[] = $observers[$instrumentId] ?? $noopObserver; + } + $callback = $this->asynchronousCallbacks[$callbackId]; + $callbacks[] = static fn () => $callback(...$args); + } + foreach ($callbacks as $callback) { + $callback(); + } + + $timestamp = $this->clock->now(); + foreach ($aggregators as $streamId => $aggregator) { + if ($stream = $this->streams[$streamId] ?? null) { + $stream->push($aggregator->collect($timestamp)); + } + } + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/MetricRegistry/MetricRegistryInterface.php b/vendor/open-telemetry/sdk/Metrics/MetricRegistry/MetricRegistryInterface.php new file mode 100644 index 000000000..e86731138 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/MetricRegistry/MetricRegistryInterface.php @@ -0,0 +1,22 @@ + */ + public array $writers = []; + + public function __construct(AttributesFactoryInterface $attributesFactory, int $timestamp) + { + $this->attributesFactory = $attributesFactory; + $this->timestamp = $timestamp; + } + + public function observe($amount, iterable $attributes = []): void + { + $context = Context::getRoot(); + $attributes = $this->attributesFactory->builder($attributes)->build(); + foreach ($this->writers as $writer) { + $writer->record($amount, $attributes, $context, $this->timestamp); + } + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/MetricRegistry/NoopObserver.php b/vendor/open-telemetry/sdk/Metrics/MetricRegistry/NoopObserver.php new file mode 100644 index 000000000..efbd94dac --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/MetricRegistry/NoopObserver.php @@ -0,0 +1,18 @@ +writer = $writer; + $this->referenceCounter = $referenceCounter; + $this->callbackId = $callbackId; + $this->callbackDestructor = $callbackDestructor; + $this->target = $target; + } + + public function detach(): void + { + if ($this->callbackId === null) { + return; + } + + $this->writer->unregisterCallback($this->callbackId); + $this->referenceCounter->release(); + if ($this->callbackDestructor !== null) { + unset($this->callbackDestructor->callbackIds[$this->callbackId]); + } + + $this->callbackId = null; + } + + public function __destruct() + { + if ($this->callbackDestructor !== null) { + return; + } + if ($this->callbackId === null) { + return; + } + + $this->referenceCounter->acquire(true); + $this->referenceCounter->release(); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/ObservableCallbackDestructor.php b/vendor/open-telemetry/sdk/Metrics/ObservableCallbackDestructor.php new file mode 100644 index 000000000..0dfea3907 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/ObservableCallbackDestructor.php @@ -0,0 +1,32 @@ + */ + public array $callbackIds = []; + private MetricWriterInterface $writer; + private ReferenceCounterInterface $referenceCounter; + + public function __construct(MetricWriterInterface $writer, ReferenceCounterInterface $referenceCounter) + { + $this->writer = $writer; + $this->referenceCounter = $referenceCounter; + } + + public function __destruct() + { + foreach ($this->callbackIds as $callbackId) { + $this->writer->unregisterCallback($callbackId); + $this->referenceCounter->release(); + } + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/ObservableCounter.php b/vendor/open-telemetry/sdk/Metrics/ObservableCounter.php new file mode 100644 index 000000000..99ae43eee --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/ObservableCounter.php @@ -0,0 +1,15 @@ +writer = $writer; + $this->instrument = $instrument; + $this->referenceCounter = $referenceCounter; + $this->destructors = $destructors; + + $this->referenceCounter->acquire(); + } + + public function __destruct() + { + $this->referenceCounter->release(); + } + + /** + * @param callable(ObserverInterface): void $callback + */ + public function observe(callable $callback): ObservableCallbackInterface + { + $callback = weaken(closure($callback), $target); + + $callbackId = $this->writer->registerCallback($callback, $this->instrument); + $this->referenceCounter->acquire(); + + $destructor = null; + if ($target) { + $destructor = $this->destructors[$target] ??= new ObservableCallbackDestructor($this->writer, $this->referenceCounter); + $destructor->callbackIds[$callbackId] = $callbackId; + } + + return new ObservableCallback($this->writer, $this->referenceCounter, $callbackId, $destructor, $target); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/ObservableUpDownCounter.php b/vendor/open-telemetry/sdk/Metrics/ObservableUpDownCounter.php new file mode 100644 index 000000000..8d21be734 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/ObservableUpDownCounter.php @@ -0,0 +1,15 @@ +stale = $stale; + $this->freshen = $freshen; + } + + public function acquire(bool $persistent = false): void + { + if ($this->count === 0) { + ($this->freshen)($this); + } + + $this->count++; + + if ($persistent) { + $this->onStale = null; + } + } + + public function release(): void + { + if (--$this->count || $this->onStale === null) { + return; + } + + ($this->stale)($this); + } + + public function onStale(Closure $callback): void + { + if ($this->onStale === null) { + return; + } + + $this->onStale[] = $callback; + } + + public function triggerStale(): void + { + assert($this->onStale !== null); + + $callbacks = $this->onStale; + $this->onStale = []; + foreach ($callbacks as $callback) { + $callback(); + } + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/StalenessHandler/DelayedStalenessHandlerFactory.php b/vendor/open-telemetry/sdk/Metrics/StalenessHandler/DelayedStalenessHandlerFactory.php new file mode 100644 index 000000000..0d719c74f --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/StalenessHandler/DelayedStalenessHandlerFactory.php @@ -0,0 +1,64 @@ +&Traversable */ + private $staleHandlers; + + /** + * @param float $delay delay in seconds + */ + public function __construct(ClockInterface $clock, float $delay) + { + $this->clock = $clock; + $this->nanoDelay = (int) ($delay * 1e9); + + $this->stale = function (DelayedStalenessHandler $handler): void { + $this->staleHandlers[$handler] = $this->clock->now(); + }; + $this->freshen = function (DelayedStalenessHandler $handler): void { + unset($this->staleHandlers[$handler]); + }; + + $this->staleHandlers = WeakMap::create(); + } + + public function create(): StalenessHandlerInterface + { + $this->triggerStaleHandlers(); + + return new DelayedStalenessHandler($this->stale, $this->freshen); + } + + private function triggerStaleHandlers(): void + { + $expired = $this->clock->now() - $this->nanoDelay; + foreach ($this->staleHandlers as $handler => $timestamp) { + if ($timestamp > $expired) { + break; + } + + /** @var DelayedStalenessHandler $handler */ + unset($this->staleHandlers[$handler]); + $handler->triggerStale(); + } + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/StalenessHandler/ImmediateStalenessHandler.php b/vendor/open-telemetry/sdk/Metrics/StalenessHandler/ImmediateStalenessHandler.php new file mode 100644 index 000000000..a5b32d5c4 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/StalenessHandler/ImmediateStalenessHandler.php @@ -0,0 +1,50 @@ +count++; + + if ($persistent) { + $this->onStale = null; + } + } + + public function release(): void + { + if (--$this->count !== 0 || !$this->onStale) { + return; + } + + $callbacks = $this->onStale; + $this->onStale = []; + foreach ($callbacks as $callback) { + $callback(); + } + } + + public function onStale(Closure $callback): void + { + if ($this->onStale === null) { + return; + } + + $this->onStale[] = $callback; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/StalenessHandler/ImmediateStalenessHandlerFactory.php b/vendor/open-telemetry/sdk/Metrics/StalenessHandler/ImmediateStalenessHandlerFactory.php new file mode 100644 index 000000000..899615dea --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/StalenessHandler/ImmediateStalenessHandlerFactory.php @@ -0,0 +1,16 @@ + */ + private array $lastReads = []; + + public function __construct(AggregationInterface $aggregation, int $startTimestamp) + { + $this->aggregation = $aggregation; + $this->startTimestamp = $startTimestamp; + $this->metric = new Metric([], [], $startTimestamp); + } + + public function temporality() + { + return Temporality::CUMULATIVE; + } + + public function timestamp(): int + { + return $this->metric->timestamp; + } + + public function push(Metric $metric): void + { + $this->metric = $metric; + } + + public function register($temporality): int + { + if ($temporality === Temporality::CUMULATIVE) { + return -1; + } + + if (($reader = array_search(null, $this->lastReads, true)) === false) { + $reader = count($this->lastReads); + } + + $this->lastReads[$reader] = $this->metric; + + return $reader; + } + + public function unregister(int $reader): void + { + if (!isset($this->lastReads[$reader])) { + return; + } + + $this->lastReads[$reader] = null; + } + + public function collect(int $reader): DataInterface + { + $metric = $this->metric; + + if (($lastRead = $this->lastReads[$reader] ?? null) === null) { + $temporality = Temporality::CUMULATIVE; + $startTimestamp = $this->startTimestamp; + } else { + $temporality = Temporality::DELTA; + $startTimestamp = $lastRead->timestamp; + + $this->lastReads[$reader] = $metric; + $metric = $this->diff($lastRead, $metric); + } + + return $this->aggregation->toData( + $metric->attributes, + $metric->summaries, + Exemplar::groupByIndex($metric->exemplars), + $startTimestamp, + $metric->timestamp, + $temporality, + ); + } + + private function diff(Metric $lastRead, Metric $metric): Metric + { + $diff = clone $metric; + foreach ($metric->summaries as $k => $summary) { + if (!isset($lastRead->summaries[$k])) { + continue; + } + + $diff->summaries[$k] = $this->aggregation->diff($lastRead->summaries[$k], $summary); + } + + return $diff; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Stream/Delta.php b/vendor/open-telemetry/sdk/Metrics/Stream/Delta.php new file mode 100644 index 000000000..a4ff56d71 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Stream/Delta.php @@ -0,0 +1,33 @@ +metric = $metric; + $this->readers = $readers; + $this->prev = $prev; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Stream/DeltaStorage.php b/vendor/open-telemetry/sdk/Metrics/Stream/DeltaStorage.php new file mode 100644 index 000000000..b46a28d65 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Stream/DeltaStorage.php @@ -0,0 +1,110 @@ +aggregation = $aggregation; + $this->head = new Delta(new Metric([], [], 0), 0); + + /** @phan-suppress-next-line PhanTypeObjectUnsetDeclaredProperty */ + unset($this->head->metric); + } + + /** + * @psalm-suppress UndefinedDocblockClass + * @phan-suppress PhanUndeclaredTypeParameter + * @param int|GMP $readers + */ + public function add(Metric $metric, $readers): void + { + /** @phpstan-ignore-next-line */ + if ($readers == 0) { + return; + } + + if (($this->head->prev->readers ?? null) != $readers) { + $this->head->prev = new Delta($metric, $readers, $this->head->prev); + } else { + assert($this->head->prev !== null); + $this->mergeInto($this->head->prev->metric, $metric); + } + } + + public function collect(int $reader, bool $retain = false): ?Metric + { + $n = null; + for ($d = $this->head; $d->prev; $d = $d->prev) { + if (($d->prev->readers >> $reader & 1) != 0) { + if ($n !== null) { + assert($n->prev !== null); + $n->prev->readers ^= $d->prev->readers; + $this->mergeInto($d->prev->metric, $n->prev->metric); + $this->tryUnlink($n); + + if ($n->prev === $d->prev) { + continue; + } + } + + $n = $d; + } + } + + $metric = $n->prev->metric ?? null; + + if (!$retain && $n) { + assert($n->prev !== null); + $n->prev->readers ^= ($n->prev->readers & 1 | 1) << $reader; + $this->tryUnlink($n); + } + + return $metric; + } + + private function tryUnlink(Delta $n): void + { + assert($n->prev !== null); + /** @phpstan-ignore-next-line */ + if ($n->prev->readers == 0) { + $n->prev = $n->prev->prev; + + return; + } + + for ($c = $n->prev->prev; + $c && ($n->prev->readers & $c->readers) == 0; + $c = $c->prev) { + } + + if ($c && $n->prev->readers === $c->readers) { + $this->mergeInto($c->metric, $n->prev->metric); + $n->prev = $n->prev->prev; + } + } + + private function mergeInto(Metric $into, Metric $metric): void + { + foreach ($metric->summaries as $k => $summary) { + $into->attributes[$k] ??= $metric->attributes[$k]; + $into->summaries[$k] = isset($into->summaries[$k]) + ? $this->aggregation->merge($into->summaries[$k], $summary) + : $summary; + } + $into->exemplars += $metric->exemplars; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Stream/Metric.php b/vendor/open-telemetry/sdk/Metrics/Stream/Metric.php new file mode 100644 index 000000000..6b1db9eef --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Stream/Metric.php @@ -0,0 +1,44 @@ + + */ + public array $attributes; + /** + * @var array + */ + public array $summaries; + public int $timestamp; + /** + * @var array + */ + public array $exemplars; + + /** + * @param array $attributes + * @param array $summaries + * @param array $exemplars + */ + public function __construct(array $attributes, array $summaries, int $timestamp, array $exemplars = []) + { + $this->attributes = $attributes; + $this->summaries = $summaries; + $this->timestamp = $timestamp; + $this->exemplars = $exemplars; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Stream/MetricAggregator.php b/vendor/open-telemetry/sdk/Metrics/Stream/MetricAggregator.php new file mode 100644 index 000000000..b1328eb07 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Stream/MetricAggregator.php @@ -0,0 +1,73 @@ + */ + private array $attributes = []; + private array $summaries = []; + + public function __construct( + ?AttributeProcessorInterface $attributeProcessor, + AggregationInterface $aggregation, + ?ExemplarReservoirInterface $exemplarReservoir = null + ) { + $this->attributeProcessor = $attributeProcessor; + $this->aggregation = $aggregation; + $this->exemplarReservoir = $exemplarReservoir; + } + + /** + * @param float|int $value + */ + public function record($value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): void + { + $filteredAttributes = $this->attributeProcessor !== null + ? $this->attributeProcessor->process($attributes, $context) + : $attributes; + $raw = $filteredAttributes->toArray(); + $index = $raw !== [] ? serialize($raw) : 0; + $this->attributes[$index] ??= $filteredAttributes; + $this->aggregation->record( + $this->summaries[$index] ??= $this->aggregation->initialize(), + $value, + $attributes, + $context, + $timestamp, + ); + + if ($this->exemplarReservoir !== null) { + $this->exemplarReservoir->offer($index, $value, $attributes, $context, $timestamp); + } + } + + public function collect(int $timestamp): Metric + { + $exemplars = $this->exemplarReservoir + ? $this->exemplarReservoir->collect($this->attributes) + : []; + $metric = new Metric($this->attributes, $this->summaries, $timestamp, $exemplars); + + $this->attributes = []; + $this->summaries = []; + + return $metric; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Stream/MetricAggregatorFactory.php b/vendor/open-telemetry/sdk/Metrics/Stream/MetricAggregatorFactory.php new file mode 100644 index 000000000..5866a72b7 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Stream/MetricAggregatorFactory.php @@ -0,0 +1,28 @@ +attributeProcessor = $attributeProcessor; + $this->aggregation = $aggregation; + } + + public function create(): MetricAggregatorInterface + { + return new MetricAggregator($this->attributeProcessor, $this->aggregation); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Stream/MetricAggregatorFactoryInterface.php b/vendor/open-telemetry/sdk/Metrics/Stream/MetricAggregatorFactoryInterface.php new file mode 100644 index 000000000..356f682f2 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Stream/MetricAggregatorFactoryInterface.php @@ -0,0 +1,13 @@ +aggregation = $aggregation; + $this->timestamp = $startTimestamp; + $this->delta = new DeltaStorage($aggregation); + } + + public function temporality() + { + return Temporality::DELTA; + } + + public function timestamp(): int + { + return $this->timestamp; + } + + public function push(Metric $metric): void + { + [$this->timestamp, $metric->timestamp] = [$metric->timestamp, $this->timestamp]; + $this->delta->add($metric, $this->readers); + } + + public function register($temporality): int + { + $reader = 0; + for ($r = $this->readers; ($r & 1) != 0; $r >>= 1, $reader++) { + } + + if ($reader === (PHP_INT_SIZE << 3) - 1 && is_int($this->readers)) { + if (!extension_loaded('gmp')) { + trigger_error(sprintf('GMP extension required to register over %d readers', (PHP_INT_SIZE << 3) - 1), E_USER_WARNING); + $reader = PHP_INT_SIZE << 3; + } else { + assert(is_int($this->cumulative)); + $this->readers = gmp_init($this->readers); + $this->cumulative = gmp_init($this->cumulative); + } + } + + $readerMask = ($this->readers & 1 | 1) << $reader; + $this->readers ^= $readerMask; + if ($temporality === Temporality::CUMULATIVE) { + $this->cumulative ^= $readerMask; + } + + return $reader; + } + + public function unregister(int $reader): void + { + $readerMask = ($this->readers & 1 | 1) << $reader; + if (($this->readers & $readerMask) == 0) { + return; + } + + $this->delta->collect($reader); + + $this->readers ^= $readerMask; + if (($this->cumulative & $readerMask) != 0) { + $this->cumulative ^= $readerMask; + } + } + + public function collect(int $reader): DataInterface + { + $cumulative = ($this->cumulative >> $reader & 1) != 0; + $metric = $this->delta->collect($reader, $cumulative) ?? new Metric([], [], $this->timestamp); + + $temporality = $cumulative + ? Temporality::CUMULATIVE + : Temporality::DELTA; + + return $this->aggregation->toData( + $metric->attributes, + $metric->summaries, + Exemplar::groupByIndex($metric->exemplars), + $metric->timestamp, + $this->timestamp, + $temporality, + ); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/Stream/WritableMetricStreamInterface.php b/vendor/open-telemetry/sdk/Metrics/Stream/WritableMetricStreamInterface.php new file mode 100644 index 000000000..9fd425a44 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/Stream/WritableMetricStreamInterface.php @@ -0,0 +1,19 @@ +writer = $writer; + $this->instrument = $instrument; + $this->referenceCounter = $referenceCounter; + + $this->referenceCounter->acquire(); + } + + public function __destruct() + { + $this->referenceCounter->release(); + } + + public function add($amount, iterable $attributes = [], $context = null): void + { + $this->writer->record($this->instrument, $amount, $attributes, $context); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/View/CriteriaViewRegistry.php b/vendor/open-telemetry/sdk/Metrics/View/CriteriaViewRegistry.php new file mode 100644 index 000000000..f387abf9c --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/View/CriteriaViewRegistry.php @@ -0,0 +1,40 @@ + */ + private array $criteria = []; + /** @var list */ + private array $views = []; + + public function register(SelectionCriteriaInterface $criteria, ViewTemplate $view): void + { + $this->criteria[] = $criteria; + $this->views[] = $view; + } + + public function find(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): ?iterable + { + $views = $this->generateViews($instrument, $instrumentationScope); + + return $views->valid() ? $views : null; + } + + private function generateViews(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): Generator + { + foreach ($this->criteria as $i => $criteria) { + if ($criteria->accepts($instrument, $instrumentationScope)) { + yield $this->views[$i]->project($instrument); + } + } + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/AllCriteria.php b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/AllCriteria.php new file mode 100644 index 000000000..438297324 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/AllCriteria.php @@ -0,0 +1,33 @@ + $criteria + */ + public function __construct(iterable $criteria) + { + $this->criteria = $criteria; + } + + public function accepts(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): bool + { + foreach ($this->criteria as $criterion) { + if (!$criterion->accepts($instrument, $instrumentationScope)) { + return false; + } + } + + return true; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentNameCriteria.php b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentNameCriteria.php new file mode 100644 index 000000000..ed6034755 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentNameCriteria.php @@ -0,0 +1,28 @@ +pattern = sprintf('/^%s$/', strtr(preg_quote($name, '/'), ['\\?' => '.', '\\*' => '.*'])); + } + + public function accepts(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): bool + { + return (bool) preg_match($this->pattern, $instrument->name); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentTypeCriteria.php b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentTypeCriteria.php new file mode 100644 index 000000000..46a88def0 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentTypeCriteria.php @@ -0,0 +1,29 @@ +instrumentTypes = (array) $instrumentType; + } + + public function accepts(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): bool + { + return in_array($instrument->type, $this->instrumentTypes, true); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeNameCriteria.php b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeNameCriteria.php new file mode 100644 index 000000000..201d1a7b2 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeNameCriteria.php @@ -0,0 +1,24 @@ +name = $name; + } + + public function accepts(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): bool + { + return $this->name === $instrumentationScope->getName(); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeSchemaUrlCriteria.php b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeSchemaUrlCriteria.php new file mode 100644 index 000000000..a11a1d589 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeSchemaUrlCriteria.php @@ -0,0 +1,24 @@ +schemaUrl = $schemaUrl; + } + + public function accepts(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): bool + { + return $this->schemaUrl === $instrumentationScope->getSchemaUrl(); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeVersionCriteria.php b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeVersionCriteria.php new file mode 100644 index 000000000..37d180f99 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteria/InstrumentationScopeVersionCriteria.php @@ -0,0 +1,24 @@ +version = $version; + } + + public function accepts(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): bool + { + return $this->version === $instrumentationScope->getVersion(); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteriaInterface.php b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteriaInterface.php new file mode 100644 index 000000000..8abd6fa69 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/View/SelectionCriteriaInterface.php @@ -0,0 +1,13 @@ + + */ + private ?array $attributeKeys = null; + private ?AggregationInterface $aggregation = null; + + private function __construct() + { + } + + public static function create(): self + { + static $instance; + + return $instance ??= new self(); + } + + public function withName(string $name): self + { + $self = clone $this; + $self->name = $name; + + return $self; + } + + public function withDescription(string $description): self + { + $self = clone $this; + $self->description = $description; + + return $self; + } + + /** + * @param list $attributeKeys + */ + public function withAttributeKeys(array $attributeKeys): self + { + $self = clone $this; + $self->attributeKeys = $attributeKeys; + + return $self; + } + + public function withAggregation(?AggregationInterface $aggregation): self + { + $self = clone $this; + $self->aggregation = $aggregation; + + return $self; + } + + public function project(Instrument $instrument): ViewProjection + { + return new ViewProjection( + $this->name ?? $instrument->name, + $instrument->unit, + $this->description ?? $instrument->description, + $this->attributeKeys, + $this->aggregation, + ); + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/ViewProjection.php b/vendor/open-telemetry/sdk/Metrics/ViewProjection.php new file mode 100644 index 000000000..046bd6bb1 --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/ViewProjection.php @@ -0,0 +1,47 @@ +|null + */ + public ?array $attributeKeys; + /** + * @readonly + */ + public ?AggregationInterface $aggregation; + + /** + * @param list|null $attributeKeys + */ + public function __construct( + string $name, + ?string $unit, + ?string $description, + ?array $attributeKeys, + ?AggregationInterface $aggregation + ) { + $this->name = $name; + $this->unit = $unit; + $this->description = $description; + $this->attributeKeys = $attributeKeys; + $this->aggregation = $aggregation; + } +} diff --git a/vendor/open-telemetry/sdk/Metrics/ViewRegistryInterface.php b/vendor/open-telemetry/sdk/Metrics/ViewRegistryInterface.php new file mode 100644 index 000000000..19d8f9ffd --- /dev/null +++ b/vendor/open-telemetry/sdk/Metrics/ViewRegistryInterface.php @@ -0,0 +1,15 @@ +|null + */ + public function find(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): ?iterable; +} diff --git a/vendor/open-telemetry/sdk/Propagation/PropagatorFactory.php b/vendor/open-telemetry/sdk/Propagation/PropagatorFactory.php new file mode 100644 index 000000000..2dc349dfb --- /dev/null +++ b/vendor/open-telemetry/sdk/Propagation/PropagatorFactory.php @@ -0,0 +1,55 @@ +buildPropagator($propagators[0]); + default: + return new MultiTextMapPropagator($this->buildPropagators($propagators)); + } + } + + /** + * @return array + */ + private function buildPropagators(array $names): array + { + $propagators = []; + foreach ($names as $name) { + $propagators[] = $this->buildPropagator($name); + } + + return $propagators; + } + + private function buildPropagator(string $name): TextMapPropagatorInterface + { + try { + return Registry::textMapPropagator($name); + } catch (\RuntimeException $e) { + self::logWarning($e->getMessage()); + } + + return NoopTextMapPropagator::getInstance(); + } +} diff --git a/vendor/open-telemetry/sdk/Propagation/_register.php b/vendor/open-telemetry/sdk/Propagation/_register.php new file mode 100644 index 000000000..fd90da184 --- /dev/null +++ b/vendor/open-telemetry/sdk/Propagation/_register.php @@ -0,0 +1,16 @@ +getTracer('example'); +$meter = \OpenTelemetry\API\Globals::meterProvider()->getMeter('example'); +``` + +If autoloading was not successful (or partially successful), no-op implementations of the above may be returned. + +See https://github.com/open-telemetry/opentelemetry-php/blob/main/examples/autoload_sdk.php for a more detailed example. + +## Contributing + +This repository is a read-only git subtree split. +To contribute, please see the main [OpenTelemetry PHP monorepo](https://github.com/open-telemetry/opentelemetry-php). diff --git a/vendor/open-telemetry/sdk/Registry.php b/vendor/open-telemetry/sdk/Registry.php new file mode 100644 index 000000000..2f0a20263 --- /dev/null +++ b/vendor/open-telemetry/sdk/Registry.php @@ -0,0 +1,208 @@ + $factory + */ + public static function registerTransportFactory(string $protocol, $factory, bool $clobber = false): void + { + if (!$clobber && array_key_exists($protocol, self::$transportFactories)) { + return; + } + if (!is_subclass_of($factory, TransportFactoryInterface::class)) { + trigger_error( + sprintf( + 'Cannot register transport factory: %s must exist and implement %s', + is_string($factory) ? $factory : get_class($factory), + TransportFactoryInterface::class + ), + E_USER_WARNING + ); + + return; + } + self::$transportFactories[$protocol] = $factory; + } + + /** + * @param SpanExporterFactoryInterface|class-string $factory + */ + public static function registerSpanExporterFactory(string $exporter, $factory, bool $clobber = false): void + { + if (!$clobber && array_key_exists($exporter, self::$spanExporterFactories)) { + return; + } + if (!is_subclass_of($factory, SpanExporterFactoryInterface::class)) { + trigger_error( + sprintf( + 'Cannot register span exporter factory: %s must exist and implement %s', + is_string($factory) ? $factory : get_class($factory), + SpanExporterFactoryInterface::class + ), + E_USER_WARNING + ); + + return; + } + self::$spanExporterFactories[$exporter] = $factory; + } + + /** + * @param MetricExporterFactoryInterface|class-string $factory + */ + public static function registerMetricExporterFactory(string $exporter, $factory, bool $clobber = false): void + { + if (!$clobber && array_key_exists($exporter, self::$metricExporterFactories)) { + return; + } + if (!is_subclass_of($factory, MetricExporterFactoryInterface::class)) { + trigger_error( + sprintf( + 'Cannot register metric factory: %s must exist and implement %s', + is_string($factory) ? $factory : get_class($factory), + MetricExporterFactoryInterface::class + ), + E_USER_WARNING + ); + + return; + } + self::$metricExporterFactories[$exporter] = $factory; + } + + public static function registerLogRecordExporterFactory(string $exporter, $factory, bool $clobber = false): void + { + if (!$clobber && array_key_exists($exporter, self::$logRecordExporterFactories)) { + return; + } + if (!is_subclass_of($factory, LogRecordExporterFactoryInterface::class)) { + trigger_error( + sprintf( + 'Cannot register LogRecord exporter factory: %s must exist and implement %s', + is_string($factory) ? $factory : get_class($factory), + LogRecordExporterFactoryInterface::class + ), + E_USER_WARNING + ); + + return; + } + self::$logRecordExporterFactories[$exporter] = $factory; + } + + public static function registerTextMapPropagator(string $name, TextMapPropagatorInterface $propagator, bool $clobber = false): void + { + if (!$clobber && array_key_exists($name, self::$textMapPropagators)) { + return; + } + self::$textMapPropagators[$name] = $propagator; + } + + public static function registerResourceDetector(string $name, ResourceDetectorInterface $detector): void + { + self::$resourceDetectors[$name] = $detector; + } + + public static function spanExporterFactory(string $exporter): SpanExporterFactoryInterface + { + if (!array_key_exists($exporter, self::$spanExporterFactories)) { + throw new RuntimeException('Span exporter factory not defined for: ' . $exporter); + } + $class = self::$spanExporterFactories[$exporter]; + $factory = (is_callable($class)) ? $class : new $class(); + assert($factory instanceof SpanExporterFactoryInterface); + + return $factory; + } + + public static function logRecordExporterFactory(string $exporter): LogRecordExporterFactoryInterface + { + if (!array_key_exists($exporter, self::$logRecordExporterFactories)) { + throw new RuntimeException('LogRecord exporter factory not defined for: ' . $exporter); + } + $class = self::$logRecordExporterFactories[$exporter]; + $factory = (is_callable($class)) ? $class : new $class(); + assert($factory instanceof LogRecordExporterFactoryInterface); + + return $factory; + } + + /** + * Get transport factory registered for protocol. If $protocol contains a content-type eg `http/xyz` then + * only the first part, `http`, is used. + */ + public static function transportFactory(string $protocol): TransportFactoryInterface + { + $protocol = explode('/', $protocol)[0]; + if (!array_key_exists($protocol, self::$transportFactories)) { + throw new RuntimeException('Transport factory not defined for protocol: ' . $protocol); + } + $class = self::$transportFactories[$protocol]; + $factory = (is_callable($class)) ? $class : new $class(); + assert($factory instanceof TransportFactoryInterface); + + return $factory; + } + + public static function metricExporterFactory(string $exporter): MetricExporterFactoryInterface + { + if (!array_key_exists($exporter, self::$metricExporterFactories)) { + throw new RuntimeException('Metric exporter factory not registered for protocol: ' . $exporter); + } + $class = self::$metricExporterFactories[$exporter]; + $factory = (is_callable($class)) ? $class : new $class(); + assert($factory instanceof MetricExporterFactoryInterface); + + return $factory; + } + + public static function textMapPropagator(string $name): TextMapPropagatorInterface + { + if (!array_key_exists($name, self::$textMapPropagators)) { + throw new RuntimeException('Text map propagator not registered for: ' . $name); + } + + return self::$textMapPropagators[$name]; + } + + public static function resourceDetector(string $name): ResourceDetectorInterface + { + if (!array_key_exists($name, self::$resourceDetectors)) { + throw new RuntimeException('Resource detector not registered for: ' . $name); + } + + return self::$resourceDetectors[$name]; + } + + /** + * @return array + */ + public static function resourceDetectors(): array + { + return array_values(self::$resourceDetectors); + } +} diff --git a/vendor/open-telemetry/sdk/Resource/Detectors/Composer.php b/vendor/open-telemetry/sdk/Resource/Detectors/Composer.php new file mode 100644 index 000000000..56b136ef1 --- /dev/null +++ b/vendor/open-telemetry/sdk/Resource/Detectors/Composer.php @@ -0,0 +1,30 @@ + InstalledVersions::getRootPackage()['name'], + ResourceAttributes::SERVICE_VERSION => InstalledVersions::getRootPackage()['pretty_version'], + ]; + + return ResourceInfo::create(Attributes::create($attributes), ResourceAttributes::SCHEMA_URL); + } +} diff --git a/vendor/open-telemetry/sdk/Resource/Detectors/Composite.php b/vendor/open-telemetry/sdk/Resource/Detectors/Composite.php new file mode 100644 index 000000000..9da267743 --- /dev/null +++ b/vendor/open-telemetry/sdk/Resource/Detectors/Composite.php @@ -0,0 +1,32 @@ + $resourceDetectors + */ + public function __construct(iterable $resourceDetectors) + { + $this->resourceDetectors = $resourceDetectors; + } + + public function getResource(): ResourceInfo + { + $resource = ResourceInfoFactory::emptyResource(); + foreach ($this->resourceDetectors as $resourceDetector) { + $resource = $resource->merge($resourceDetector->getResource()); + } + + return $resource; + } +} diff --git a/vendor/open-telemetry/sdk/Resource/Detectors/Constant.php b/vendor/open-telemetry/sdk/Resource/Detectors/Constant.php new file mode 100644 index 000000000..7ff9d19eb --- /dev/null +++ b/vendor/open-telemetry/sdk/Resource/Detectors/Constant.php @@ -0,0 +1,23 @@ +resourceInfo = $resourceInfo; + } + + public function getResource(): ResourceInfo + { + return $this->resourceInfo; + } +} diff --git a/vendor/open-telemetry/sdk/Resource/Detectors/Environment.php b/vendor/open-telemetry/sdk/Resource/Detectors/Environment.php new file mode 100644 index 000000000..ceee8fcf7 --- /dev/null +++ b/vendor/open-telemetry/sdk/Resource/Detectors/Environment.php @@ -0,0 +1,40 @@ + php_uname('n'), + ResourceAttributes::HOST_ARCH => php_uname('m'), + ]; + + return ResourceInfo::create(Attributes::create($attributes), ResourceAttributes::SCHEMA_URL); + } +} diff --git a/vendor/open-telemetry/sdk/Resource/Detectors/OperatingSystem.php b/vendor/open-telemetry/sdk/Resource/Detectors/OperatingSystem.php new file mode 100644 index 000000000..2cb350dc2 --- /dev/null +++ b/vendor/open-telemetry/sdk/Resource/Detectors/OperatingSystem.php @@ -0,0 +1,32 @@ + strtolower(PHP_OS_FAMILY), + ResourceAttributes::OS_DESCRIPTION => php_uname('r'), + ResourceAttributes::OS_NAME => PHP_OS, + ResourceAttributes::OS_VERSION => php_uname('v'), + ]; + + return ResourceInfo::create(Attributes::create($attributes), ResourceAttributes::SCHEMA_URL); + } +} diff --git a/vendor/open-telemetry/sdk/Resource/Detectors/Process.php b/vendor/open-telemetry/sdk/Resource/Detectors/Process.php new file mode 100644 index 000000000..7f1d99386 --- /dev/null +++ b/vendor/open-telemetry/sdk/Resource/Detectors/Process.php @@ -0,0 +1,43 @@ + php_sapi_name(), + ResourceAttributes::PROCESS_RUNTIME_VERSION => PHP_VERSION, + ]; + + return ResourceInfo::create(Attributes::create($attributes), ResourceAttributes::SCHEMA_URL); + } +} diff --git a/vendor/open-telemetry/sdk/Resource/Detectors/Sdk.php b/vendor/open-telemetry/sdk/Resource/Detectors/Sdk.php new file mode 100644 index 000000000..dba3eb8aa --- /dev/null +++ b/vendor/open-telemetry/sdk/Resource/Detectors/Sdk.php @@ -0,0 +1,53 @@ + 'opentelemetry', + ResourceAttributes::TELEMETRY_SDK_LANGUAGE => 'php', + ]; + + if (class_exists(InstalledVersions::class)) { + foreach (self::PACKAGES as $package) { + if (!InstalledVersions::isInstalled($package)) { + continue; + } + if (($version = InstalledVersions::getPrettyVersion($package)) === null) { + continue; + } + + $attributes[ResourceAttributes::TELEMETRY_SDK_VERSION] = $version; + + break; + } + } + + if (extension_loaded('opentelemetry')) { + $attributes[ResourceAttributes::TELEMETRY_DISTRO_NAME] = 'opentelemetry-php-instrumentation'; + $attributes[ResourceAttributes::TELEMETRY_DISTRO_VERSION] = phpversion('opentelemetry'); + } + + return ResourceInfo::create(Attributes::create($attributes), ResourceAttributes::SCHEMA_URL); + } +} diff --git a/vendor/open-telemetry/sdk/Resource/Detectors/SdkProvided.php b/vendor/open-telemetry/sdk/Resource/Detectors/SdkProvided.php new file mode 100644 index 000000000..ec4ec7def --- /dev/null +++ b/vendor/open-telemetry/sdk/Resource/Detectors/SdkProvided.php @@ -0,0 +1,25 @@ + 'unknown_service:php', + ]; + + return ResourceInfo::create(Attributes::create($attributes), ResourceAttributes::SCHEMA_URL); + } +} diff --git a/vendor/open-telemetry/sdk/Resource/ResourceDetectorInterface.php b/vendor/open-telemetry/sdk/Resource/ResourceDetectorInterface.php new file mode 100644 index 000000000..f2cd5256b --- /dev/null +++ b/vendor/open-telemetry/sdk/Resource/ResourceDetectorInterface.php @@ -0,0 +1,10 @@ +attributes = $attributes; + $this->schemaUrl = $schemaUrl; + } + + public static function create(AttributesInterface $attributes, ?string $schemaUrl = null): self + { + return new ResourceInfo($attributes, $schemaUrl); + } + + public function getAttributes(): AttributesInterface + { + return $this->attributes; + } + + public function getSchemaUrl(): ?string + { + return $this->schemaUrl; + } + + public function serialize(): string + { + $copyOfAttributesAsArray = array_slice($this->attributes->toArray(), 0); //This may be overly cautious (in trying to avoid mutating the source array) + ksort($copyOfAttributesAsArray); //sort the associative array by keys since the serializer will consider equal arrays different otherwise + + //The exact return value doesn't matter, as long as it can distingusih between instances that represent the same/different resources + return serialize([ + 'schemaUrl' => $this->schemaUrl, + 'attributes' => $copyOfAttributesAsArray, + ]); + } + + /** + * Merge current resource with an updating resource, combining all attributes. If a key exists on both the old and updating + * resource, the value of the updating resource MUST be picked (even if the updated value is empty) + * + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/resource/sdk.md#merge + */ + public function merge(ResourceInfo $updating): ResourceInfo + { + $schemaUrl = self::mergeSchemaUrl($this->getSchemaUrl(), $updating->getSchemaUrl()); + $attributes = $updating->getAttributes()->toArray() + $this->getAttributes()->toArray(); + + return ResourceInfo::create(Attributes::create($attributes), $schemaUrl); + } + + /** + * Merge the schema URLs from the old and updating resource. + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/resource/sdk.md#merge + */ + private static function mergeSchemaUrl(?string $old, ?string $updating): ?string + { + if (empty($old)) { + return $updating; + } + if (empty($updating)) { + return $old; + } + if ($old === $updating) { + return $old; + } + + self::logWarning('Merging resources with different schema URLs', [ + 'old' => $old, + 'updating' => $updating, + ]); + + return null; + } + + /** + * @codeCoverageIgnore + */ + public static function defaultResource(): ResourceInfo + { + BcUtil::triggerMethodDeprecationNotice( + __METHOD__, + 'defaultResource', + ResourceInfoFactory::class + ); + + return ResourceInfoFactory::defaultResource(); + } + + /** + * @codeCoverageIgnore + */ + public static function emptyResource(): ResourceInfo + { + BcUtil::triggerMethodDeprecationNotice( + __METHOD__, + 'emptyResource', + ResourceInfoFactory::class + ); + + return ResourceInfoFactory::emptyResource(); + } +} diff --git a/vendor/open-telemetry/sdk/Resource/ResourceInfoFactory.php b/vendor/open-telemetry/sdk/Resource/ResourceInfoFactory.php new file mode 100644 index 000000000..7fc80bcd9 --- /dev/null +++ b/vendor/open-telemetry/sdk/Resource/ResourceInfoFactory.php @@ -0,0 +1,95 @@ +getResource(); + } + + $resourceDetectors = []; + + foreach ($detectors as $detector) { + switch ($detector) { + case Values::VALUE_DETECTORS_ENVIRONMENT: + $resourceDetectors[] = new Detectors\Environment(); + + break; + case Values::VALUE_DETECTORS_HOST: + $resourceDetectors[] = new Detectors\Host(); + + break; + case Values::VALUE_DETECTORS_OS: + $resourceDetectors[] = new Detectors\OperatingSystem(); + + break; + case Values::VALUE_DETECTORS_PROCESS: + $resourceDetectors[] = new Detectors\Process(); + + break; + case Values::VALUE_DETECTORS_PROCESS_RUNTIME: + $resourceDetectors[] = new Detectors\ProcessRuntime(); + + break; + case Values::VALUE_DETECTORS_SDK: + $resourceDetectors[] = new Detectors\Sdk(); + + break; + case Values::VALUE_DETECTORS_SDK_PROVIDED: + $resourceDetectors[] = new Detectors\SdkProvided(); + + break; + + case Values::VALUE_DETECTORS_COMPOSER: + $resourceDetectors[] = new Detectors\Composer(); + + break; + case Values::VALUE_NONE: + + break; + default: + try { + $resourceDetectors[] = Registry::resourceDetector($detector); + } catch (RuntimeException $e) { + self::logWarning($e->getMessage()); + } + } + } + + return (new Detectors\Composite($resourceDetectors))->getResource(); + } + + public static function emptyResource(): ResourceInfo + { + return ResourceInfo::create(Attributes::create([])); + } +} diff --git a/vendor/open-telemetry/sdk/Sdk.php b/vendor/open-telemetry/sdk/Sdk.php new file mode 100644 index 000000000..3b63eb93a --- /dev/null +++ b/vendor/open-telemetry/sdk/Sdk.php @@ -0,0 +1,70 @@ +tracerProvider = $tracerProvider; + $this->meterProvider = $meterProvider; + $this->loggerProvider = $loggerProvider; + $this->propagator = $propagator; + } + + public static function isDisabled(): bool + { + return Configuration::getBoolean(Variables::OTEL_SDK_DISABLED); + } + + /** + * Tests whether an auto-instrumentation package has been disabled by config + */ + public static function isInstrumentationDisabled(string $name): bool + { + return in_array($name, Configuration::getList(Variables::OTEL_PHP_DISABLED_INSTRUMENTATIONS)); + } + + public static function builder(): SdkBuilder + { + return new SdkBuilder(); + } + + public function getTracerProvider(): TracerProviderInterface + { + return $this->tracerProvider; + } + + public function getMeterProvider(): MeterProviderInterface + { + return $this->meterProvider; + } + + public function getLoggerProvider(): LoggerProviderInterface + { + return $this->loggerProvider; + } + + public function getPropagator(): TextMapPropagatorInterface + { + return $this->propagator; + } +} diff --git a/vendor/open-telemetry/sdk/SdkAutoloader.php b/vendor/open-telemetry/sdk/SdkAutoloader.php new file mode 100644 index 000000000..c08195e19 --- /dev/null +++ b/vendor/open-telemetry/sdk/SdkAutoloader.php @@ -0,0 +1,76 @@ +create(); + if (Sdk::isDisabled()) { + //@see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#general-sdk-configuration + return $configurator->withPropagator($propagator); + } + $emitMetrics = Configuration::getBoolean(Variables::OTEL_PHP_INTERNAL_METRICS_ENABLED); + + $exporter = (new ExporterFactory())->create(); + $meterProvider = (new MeterProviderFactory())->create(); + $spanProcessor = (new SpanProcessorFactory())->create($exporter, $emitMetrics ? $meterProvider : null); + $tracerProvider = (new TracerProviderBuilder()) + ->addSpanProcessor($spanProcessor) + ->setSampler((new SamplerFactory())->create()) + ->build(); + + $loggerProvider = (new LoggerProviderFactory())->create($emitMetrics ? $meterProvider : null); + + ShutdownHandler::register([$tracerProvider, 'shutdown']); + ShutdownHandler::register([$meterProvider, 'shutdown']); + ShutdownHandler::register([$loggerProvider, 'shutdown']); + + return $configurator + ->withTracerProvider($tracerProvider) + ->withMeterProvider($meterProvider) + ->withLoggerProvider($loggerProvider) + ->withPropagator($propagator) + ; + }); + + return true; + } + + /** + * @internal + */ + public static function reset(): void + { + self::$enabled = null; + } +} diff --git a/vendor/open-telemetry/sdk/SdkBuilder.php b/vendor/open-telemetry/sdk/SdkBuilder.php new file mode 100644 index 000000000..2090c4731 --- /dev/null +++ b/vendor/open-telemetry/sdk/SdkBuilder.php @@ -0,0 +1,98 @@ +autoShutdown = $shutdown; + + return $this; + } + + public function setTracerProvider(TracerProviderInterface $provider): self + { + $this->tracerProvider = $provider; + + return $this; + } + + public function setMeterProvider(MeterProviderInterface $meterProvider): self + { + $this->meterProvider = $meterProvider; + + return $this; + } + + public function setLoggerProvider(LoggerProviderInterface $loggerProvider): self + { + $this->loggerProvider = $loggerProvider; + + return $this; + } + + public function setPropagator(TextMapPropagatorInterface $propagator): self + { + $this->propagator = $propagator; + + return $this; + } + + public function build(): Sdk + { + $tracerProvider = $this->tracerProvider ?? new NoopTracerProvider(); + $meterProvider = $this->meterProvider ?? new NoopMeterProvider(); + $loggerProvider = $this->loggerProvider ?? new NoopLoggerProvider(); + if ($this->autoShutdown) { + // rector rule disabled in config, because ShutdownHandler::register() does not keep a strong reference to $this + ShutdownHandler::register([$tracerProvider, 'shutdown']); + ShutdownHandler::register([$meterProvider, 'shutdown']); + ShutdownHandler::register([$loggerProvider, 'shutdown']); + } + + return new Sdk( + $tracerProvider, + $meterProvider, + $loggerProvider, + $this->propagator ?? NoopTextMapPropagator::getInstance(), + ); + } + + public function buildAndRegisterGlobal(): ScopeInterface + { + $sdk = $this->build(); + $context = Configurator::create() + ->withPropagator($sdk->getPropagator()) + ->withTracerProvider($sdk->getTracerProvider()) + ->withMeterProvider($sdk->getMeterProvider()) + ->withLoggerProvider($sdk->getLoggerProvider()) + ->storeInContext(); + + return Context::storage()->attach($context); + } +} diff --git a/vendor/open-telemetry/sdk/Trace/Behavior/LoggerAwareTrait.php b/vendor/open-telemetry/sdk/Trace/Behavior/LoggerAwareTrait.php new file mode 100644 index 000000000..24f5e56a8 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/Behavior/LoggerAwareTrait.php @@ -0,0 +1,48 @@ +defaultLogLevel = $logLevel; + } + + /** + * @param string $message + * @param array $context + * @param string|null $level + */ + protected function log(string $message, array $context = [], ?string $level = null): void + { + $this->getLogger()->log( + $level ?? $this->defaultLogLevel, + $message, + $context + ); + } + + protected function getLogger(): LoggerInterface + { + if ($this->logger !== null) { + return $this->logger; + } + + return new NullLogger(); + } +} diff --git a/vendor/open-telemetry/sdk/Trace/Behavior/SpanExporterDecoratorTrait.php b/vendor/open-telemetry/sdk/Trace/Behavior/SpanExporterDecoratorTrait.php new file mode 100644 index 000000000..97839ec5b --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/Behavior/SpanExporterDecoratorTrait.php @@ -0,0 +1,47 @@ + $batch + * @return FutureInterface + */ + public function export(iterable $batch, ?CancellationInterface $cancellation = null): FutureInterface + { + $batch = $this->beforeExport($batch); + $response = $this->decorated->export($batch, $cancellation); + $response->map(fn (bool $result) => $this->afterExport($batch, $result)); + + return $response; + } + + abstract protected function beforeExport(iterable $spans): iterable; + + abstract protected function afterExport(iterable $spans, bool $exportSuccess): void; + + public function shutdown(?CancellationInterface $cancellation = null): bool + { + return $this->decorated->shutdown($cancellation); + } + + public function forceFlush(?CancellationInterface $cancellation = null): bool + { + return $this->decorated->forceFlush($cancellation); + } + + public function setDecorated(SpanExporterInterface $decorated): void + { + $this->decorated = $decorated; + } +} diff --git a/vendor/open-telemetry/sdk/Trace/Behavior/SpanExporterTrait.php b/vendor/open-telemetry/sdk/Trace/Behavior/SpanExporterTrait.php new file mode 100644 index 000000000..339fecc1d --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/Behavior/SpanExporterTrait.php @@ -0,0 +1,47 @@ +running = false; + + return true; + } + + /** @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/specification/trace/sdk.md#forceflush-2 */ + public function forceFlush(?CancellationInterface $cancellation = null): bool + { + return true; + } + + /** + * @param iterable $batch + * @return FutureInterface + */ + public function export(iterable $batch, ?CancellationInterface $cancellation = null): FutureInterface + { + if (!$this->running) { + return new CompletedFuture(false); + } + + return new CompletedFuture($this->doExport($batch)); /** @phpstan-ignore-line */ + } + + /** + * @param iterable $spans Batch of spans to export + */ + abstract protected function doExport(iterable $spans): bool; /** @phpstan-ignore-line */ +} diff --git a/vendor/open-telemetry/sdk/Trace/Behavior/UsesSpanConverterTrait.php b/vendor/open-telemetry/sdk/Trace/Behavior/UsesSpanConverterTrait.php new file mode 100644 index 000000000..4802cd15b --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/Behavior/UsesSpanConverterTrait.php @@ -0,0 +1,41 @@ +converter = $converter; + } + + public function getSpanConverter(): SpanConverterInterface + { + if (null === $this->converter) { + $this->converter = new NullSpanConverter(); + } + + return $this->converter; + } + + /** + * @param SpanDataInterface $span + * @return array + * @psalm-suppress PossiblyNullReference + */ + protected function convertSpan(SpanDataInterface $span): array + { + return $this->getSpanConverter()->convert([$span]); + } +} diff --git a/vendor/open-telemetry/sdk/Trace/Event.php b/vendor/open-telemetry/sdk/Trace/Event.php new file mode 100644 index 000000000..28cb39bb1 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/Event.php @@ -0,0 +1,47 @@ +name = $name; + $this->timestamp = $timestamp; + $this->attributes = $attributes; + } + + public function getAttributes(): AttributesInterface + { + return $this->attributes; + } + + public function getName(): string + { + return $this->name; + } + + public function getEpochNanos(): int + { + return $this->timestamp; + } + + public function getTotalAttributeCount(): int + { + return count($this->attributes); + } + + public function getDroppedAttributesCount(): int + { + return $this->attributes->getDroppedAttributesCount(); + } +} diff --git a/vendor/open-telemetry/sdk/Trace/EventInterface.php b/vendor/open-telemetry/sdk/Trace/EventInterface.php new file mode 100644 index 000000000..8b5ee2af6 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/EventInterface.php @@ -0,0 +1,15 @@ +create(); + } +} diff --git a/vendor/open-telemetry/sdk/Trace/IdGeneratorInterface.php b/vendor/open-telemetry/sdk/Trace/IdGeneratorInterface.php new file mode 100644 index 000000000..ad622dccc --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/IdGeneratorInterface.php @@ -0,0 +1,12 @@ + */ + private array $events; + + /** @var list */ + private array $links; + + private AttributesInterface $attributes; + private int $totalRecordedEvents; + private StatusDataInterface $status; + private int $endEpochNanos; + private bool $hasEnded; + + /** + * @param non-empty-string $name + * @param list $links + * @param list $events + */ + public function __construct( + Span $span, + string $name, + array $links, + array $events, + AttributesInterface $attributes, + int $totalRecordedEvents, + StatusDataInterface $status, + int $endEpochNanos, + bool $hasEnded + ) { + $this->span = $span; + $this->name = $name; + $this->links = $links; + $this->events = $events; + $this->attributes = $attributes; + $this->totalRecordedEvents = $totalRecordedEvents; + $this->status = $status; + $this->endEpochNanos = $endEpochNanos; + $this->hasEnded = $hasEnded; + } + + public function getKind(): int + { + return $this->span->getKind(); + } + + public function getContext(): API\SpanContextInterface + { + return $this->span->getContext(); + } + + public function getParentContext(): API\SpanContextInterface + { + return $this->span->getParentContext(); + } + + public function getTraceId(): string + { + return $this->getContext()->getTraceId(); + } + + public function getSpanId(): string + { + return $this->getContext()->getSpanId(); + } + + public function getParentSpanId(): string + { + return $this->getParentContext()->getSpanId(); + } + + public function getStartEpochNanos(): int + { + return $this->span->getStartEpochNanos(); + } + + public function getEndEpochNanos(): int + { + return $this->endEpochNanos; + } + + public function getInstrumentationScope(): InstrumentationScopeInterface + { + return $this->span->getInstrumentationScope(); + } + + public function getResource(): ResourceInfo + { + return $this->span->getResource(); + } + + public function getName(): string + { + return $this->name; + } + + /** @inheritDoc */ + public function getLinks(): array + { + return $this->links; + } + + /** @inheritDoc */ + public function getEvents(): array + { + return $this->events; + } + + public function getAttributes(): AttributesInterface + { + return $this->attributes; + } + + public function getTotalDroppedEvents(): int + { + return max(0, $this->totalRecordedEvents - count($this->events)); + } + + public function getTotalDroppedLinks(): int + { + return max(0, $this->span->getTotalRecordedLinks() - count($this->links)); + } + + public function getStatus(): StatusDataInterface + { + return $this->status; + } + + public function hasEnded(): bool + { + return $this->hasEnded; + } +} diff --git a/vendor/open-telemetry/sdk/Trace/Link.php b/vendor/open-telemetry/sdk/Trace/Link.php new file mode 100644 index 000000000..9927839e7 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/Link.php @@ -0,0 +1,30 @@ +context = $context; + $this->attributes = $attributes; + } + + public function getSpanContext(): API\SpanContextInterface + { + return $this->context; + } + + public function getAttributes(): AttributesInterface + { + return $this->attributes; + } +} diff --git a/vendor/open-telemetry/sdk/Trace/LinkInterface.php b/vendor/open-telemetry/sdk/Trace/LinkInterface.php new file mode 100644 index 000000000..8090fa1a5 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/LinkInterface.php @@ -0,0 +1,14 @@ +randomHex(self::TRACE_ID_HEX_LENGTH); + } while (!SpanContextValidator::isValidTraceId($traceId)); + + return $traceId; + } + + public function generateSpanId(): string + { + do { + $spanId = $this->randomHex(self::SPAN_ID_HEX_LENGTH); + } while (!SpanContextValidator::isValidSpanId($spanId)); + + return $spanId; + } + + /** + * @psalm-suppress ArgumentTypeCoercion $hexLength is always a positive integer + */ + private function randomHex(int $hexLength): string + { + try { + return bin2hex(random_bytes(intdiv($hexLength, 2))); + } catch (Throwable $e) { + return $this->fallbackAlgorithm($hexLength); + } + } + + private function fallbackAlgorithm(int $hexLength): string + { + return substr(str_shuffle(str_repeat('0123456789abcdef', $hexLength)), 1, $hexLength); + } +} diff --git a/vendor/open-telemetry/sdk/Trace/ReadWriteSpanInterface.php b/vendor/open-telemetry/sdk/Trace/ReadWriteSpanInterface.php new file mode 100644 index 000000000..60940ac01 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/ReadWriteSpanInterface.php @@ -0,0 +1,11 @@ +getContext(); + $traceState = $parentSpanContext->getTraceState(); + + return new SamplingResult( + SamplingResult::DROP, + [], + $traceState + ); + } + + public function getDescription(): string + { + return 'AlwaysOffSampler'; + } +} diff --git a/vendor/open-telemetry/sdk/Trace/Sampler/AlwaysOnSampler.php b/vendor/open-telemetry/sdk/Trace/Sampler/AlwaysOnSampler.php new file mode 100644 index 000000000..df61d1aee --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/Sampler/AlwaysOnSampler.php @@ -0,0 +1,50 @@ +getContext(); + $traceState = $parentSpanContext->getTraceState(); + + return new SamplingResult( + SamplingResult::RECORD_AND_SAMPLE, + [], + $traceState + ); + } + + public function getDescription(): string + { + return 'AlwaysOnSampler'; + } +} diff --git a/vendor/open-telemetry/sdk/Trace/Sampler/ParentBased.php b/vendor/open-telemetry/sdk/Trace/Sampler/ParentBased.php new file mode 100644 index 000000000..db801d3d8 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/Sampler/ParentBased.php @@ -0,0 +1,100 @@ +root = $root; + $this->remoteParentSampler = $remoteParentSampler ?? new AlwaysOnSampler(); + $this->remoteParentNotSampler = $remoteParentNotSampler ?? new AlwaysOffSampler(); + $this->localParentSampler = $localParentSampler ?? new AlwaysOnSampler(); + $this->localParentNotSampler = $localParentNotSampler ?? new AlwaysOffSampler(); + } + + /** + * Invokes the respective delegate sampler when parent is set or uses root sampler for the root span. + * {@inheritdoc} + */ + public function shouldSample( + ContextInterface $parentContext, + string $traceId, + string $spanName, + int $spanKind, + AttributesInterface $attributes, + array $links + ): SamplingResult { + $parentSpan = Span::fromContext($parentContext); + $parentSpanContext = $parentSpan->getContext(); + + // Invalid parent SpanContext indicates root span is being created + if (!$parentSpanContext->isValid()) { + return $this->root->shouldSample(...func_get_args()); + } + + if ($parentSpanContext->isRemote()) { + return $parentSpanContext->isSampled() + ? $this->remoteParentSampler->shouldSample(...func_get_args()) + : $this->remoteParentNotSampler->shouldSample(...func_get_args()); + } + + return $parentSpanContext->isSampled() + ? $this->localParentSampler->shouldSample(...func_get_args()) + : $this->localParentNotSampler->shouldSample(...func_get_args()); + } + + public function getDescription(): string + { + return 'ParentBased+' . $this->root->getDescription(); + } +} diff --git a/vendor/open-telemetry/sdk/Trace/Sampler/TraceIdRatioBasedSampler.php b/vendor/open-telemetry/sdk/Trace/Sampler/TraceIdRatioBasedSampler.php new file mode 100644 index 000000000..c11a90d5d --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/Sampler/TraceIdRatioBasedSampler.php @@ -0,0 +1,70 @@ + 1.0) { + throw new InvalidArgumentException('probability should be be between 0.0 and 1.0.'); + } + $this->probability = $probability; + } + + /** + * Returns `SamplingResult` based on probability. Respects the parent `SampleFlag` + * {@inheritdoc} + */ + public function shouldSample( + ContextInterface $parentContext, + string $traceId, + string $spanName, + int $spanKind, + AttributesInterface $attributes, + array $links + ): SamplingResult { + // TODO: Add config to adjust which spans get sampled (only default from specification is implemented) + $parentSpan = Span::fromContext($parentContext); + $parentSpanContext = $parentSpan->getContext(); + $traceState = $parentSpanContext->getTraceState(); + + /** + * Since php can only store up to 63 bit positive integers + */ + $traceIdLimit = (1 << 60) - 1; + $lowerOrderBytes = hexdec(substr($traceId, strlen($traceId) - 15, 15)); + $traceIdCondition = $lowerOrderBytes < round($this->probability * $traceIdLimit); + $decision = $traceIdCondition ? SamplingResult::RECORD_AND_SAMPLE : SamplingResult::DROP; + + return new SamplingResult($decision, [], $traceState); + } + + public function getDescription(): string + { + return sprintf('%s{%.6F}', 'TraceIdRatioBasedSampler', $this->probability); + } +} diff --git a/vendor/open-telemetry/sdk/Trace/SamplerFactory.php b/vendor/open-telemetry/sdk/Trace/SamplerFactory.php new file mode 100644 index 000000000..f99674d79 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SamplerFactory.php @@ -0,0 +1,48 @@ + $links Collection of links that will be associated with the Span to be created. + * Typically, useful for batch operations. + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md#links-between-spans + * @return SamplingResult + */ + public function shouldSample( + ContextInterface $parentContext, + string $traceId, + string $spanName, + int $spanKind, + AttributesInterface $attributes, + array $links + ): SamplingResult; + + /** + * Returns the sampler name or short description with the configuration. + * This may be displayed on debug pages or in the logs. + * Example: "TraceIdRatioBasedSampler{0.000100}" + */ + public function getDescription(): string; +} diff --git a/vendor/open-telemetry/sdk/Trace/SamplingResult.php b/vendor/open-telemetry/sdk/Trace/SamplingResult.php new file mode 100644 index 000000000..5701b7bc6 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SamplingResult.php @@ -0,0 +1,71 @@ +decision = $decision; + $this->attributes = $attributes; + $this->traceState = $traceState; + } + + /** + * Return sampling decision whether span should be recorded or not. + */ + public function getDecision(): int + { + return $this->decision; + } + + /** + * Return attributes which will be attached to the span. + */ + public function getAttributes(): iterable + { + return $this->attributes; + } + + /** + * Return a collection of links that will be associated with the Span to be created. + */ + public function getTraceState(): ?API\TraceStateInterface + { + return $this->traceState; + } +} diff --git a/vendor/open-telemetry/sdk/Trace/Span.php b/vendor/open-telemetry/sdk/Trace/Span.php new file mode 100644 index 000000000..f72ec1bd7 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/Span.php @@ -0,0 +1,359 @@ + + */ + private array $links; + + /** @readonly */ + private int $totalRecordedLinks; + + /** @readonly */ + private int $kind; + + /** @readonly */ + private ResourceInfo $resource; + + /** @readonly */ + private InstrumentationScopeInterface $instrumentationScope; + + /** @readonly */ + private int $startEpochNanos; + + /** @var non-empty-string */ + private string $name; + + /** @var list */ + private array $events = []; + + private AttributesBuilderInterface $attributesBuilder; + private int $totalRecordedEvents = 0; + private StatusDataInterface $status; + private int $endEpochNanos = 0; + private bool $hasEnded = false; + + /** + * @param non-empty-string $name + * @param list $links + */ + private function __construct( + string $name, + API\SpanContextInterface $context, + InstrumentationScopeInterface $instrumentationScope, + int $kind, + API\SpanContextInterface $parentSpanContext, + SpanLimits $spanLimits, + SpanProcessorInterface $spanProcessor, + ResourceInfo $resource, + AttributesBuilderInterface $attributesBuilder, + array $links, + int $totalRecordedLinks, + int $startEpochNanos + ) { + $this->context = $context; + $this->instrumentationScope = $instrumentationScope; + $this->parentSpanContext = $parentSpanContext; + $this->links = $links; + $this->totalRecordedLinks = $totalRecordedLinks; + $this->name = $name; + $this->kind = $kind; + $this->spanProcessor = $spanProcessor; + $this->resource = $resource; + $this->startEpochNanos = $startEpochNanos; + $this->attributesBuilder = $attributesBuilder; + $this->status = StatusData::unset(); + $this->spanLimits = $spanLimits; + } + + /** + * This method _MUST_ not be used directly. + * End users should use a {@see API\TracerInterface} in order to create spans. + * + * @param non-empty-string $name + * @psalm-param API\SpanKind::KIND_* $kind + * @param list $links + * + * @internal + * @psalm-internal OpenTelemetry + */ + public static function startSpan( + string $name, + API\SpanContextInterface $context, + InstrumentationScopeInterface $instrumentationScope, + int $kind, + API\SpanInterface $parentSpan, + ContextInterface $parentContext, + SpanLimits $spanLimits, + SpanProcessorInterface $spanProcessor, + ResourceInfo $resource, + AttributesBuilderInterface $attributesBuilder, + array $links, + int $totalRecordedLinks, + int $startEpochNanos + ): self { + $span = new self( + $name, + $context, + $instrumentationScope, + $kind, + $parentSpan->getContext(), + $spanLimits, + $spanProcessor, + $resource, + $attributesBuilder, + $links, + $totalRecordedLinks, + $startEpochNanos !== 0 ? $startEpochNanos : ClockFactory::getDefault()->now() + ); + + // Call onStart here to ensure the span is fully initialized. + $spanProcessor->onStart($span, $parentContext); + + return $span; + } + + /** + * Backward compatibility methods + * + * @codeCoverageIgnore + */ + public static function formatStackTrace(Throwable $e, array &$seen = null): string + { + BcUtil::triggerMethodDeprecationNotice( + __METHOD__, + 'format', + StackTraceFormatter::class + ); + + return StackTraceFormatter::format($e); + } + + /** @inheritDoc */ + public function getContext(): API\SpanContextInterface + { + return $this->context; + } + + /** @inheritDoc */ + public function isRecording(): bool + { + return !$this->hasEnded; + } + + /** @inheritDoc */ + public function setAttribute(string $key, $value): self + { + if ($this->hasEnded) { + return $this; + } + + $this->attributesBuilder[$key] = $value; + + return $this; + } + + /** @inheritDoc */ + public function setAttributes(iterable $attributes): self + { + foreach ($attributes as $key => $value) { + $this->attributesBuilder[$key] = $value; + } + + return $this; + } + + /** @inheritDoc */ + public function addEvent(string $name, iterable $attributes = [], ?int $timestamp = null): self + { + if ($this->hasEnded) { + return $this; + } + if (++$this->totalRecordedEvents > $this->spanLimits->getEventCountLimit()) { + return $this; + } + + $timestamp ??= ClockFactory::getDefault()->now(); + $eventAttributesBuilder = $this->spanLimits->getEventAttributesFactory()->builder($attributes); + + $this->events[] = new Event($name, $timestamp, $eventAttributesBuilder->build()); + + return $this; + } + + /** @inheritDoc */ + public function recordException(Throwable $exception, iterable $attributes = [], ?int $timestamp = null): self + { + if ($this->hasEnded) { + return $this; + } + if (++$this->totalRecordedEvents > $this->spanLimits->getEventCountLimit()) { + return $this; + } + + $timestamp ??= ClockFactory::getDefault()->now(); + $eventAttributesBuilder = $this->spanLimits->getEventAttributesFactory()->builder([ + 'exception.type' => get_class($exception), + 'exception.message' => $exception->getMessage(), + 'exception.stacktrace' => StackTraceFormatter::format($exception), + ]); + + foreach ($attributes as $key => $value) { + $eventAttributesBuilder[$key] = $value; + } + + $this->events[] = new Event('exception', $timestamp, $eventAttributesBuilder->build()); + + return $this; + } + + /** @inheritDoc */ + public function updateName(string $name): self + { + if ($this->hasEnded) { + return $this; + } + $this->name = $name; + + return $this; + } + + /** @inheritDoc */ + public function setStatus(string $code, string $description = null): self + { + if ($this->hasEnded) { + return $this; + } + + // An attempt to set value Unset SHOULD be ignored. + if ($code === API\StatusCode::STATUS_UNSET) { + return $this; + } + + // When span status is set to Ok it SHOULD be considered final and any further attempts to change it SHOULD be ignored. + if ($this->status->getCode() === API\StatusCode::STATUS_OK) { + return $this; + } + $this->status = StatusData::create($code, $description); + + return $this; + } + + /** @inheritDoc */ + public function end(int $endEpochNanos = null): void + { + if ($this->hasEnded) { + return; + } + + $this->endEpochNanos = $endEpochNanos ?? ClockFactory::getDefault()->now(); + $this->hasEnded = true; + + $this->spanProcessor->onEnd($this); + } + + /** @inheritDoc */ + public function getName(): string + { + return $this->name; + } + + public function getParentContext(): API\SpanContextInterface + { + return $this->parentSpanContext; + } + + public function getInstrumentationScope(): InstrumentationScopeInterface + { + return $this->instrumentationScope; + } + + public function hasEnded(): bool + { + return $this->hasEnded; + } + + public function toSpanData(): SpanDataInterface + { + return new ImmutableSpan( + $this, + $this->name, + $this->links, + $this->events, + $this->attributesBuilder->build(), + $this->totalRecordedEvents, + $this->status, + $this->endEpochNanos, + $this->hasEnded + ); + } + + /** @inheritDoc */ + public function getDuration(): int + { + return ($this->hasEnded ? $this->endEpochNanos : ClockFactory::getDefault()->now()) - $this->startEpochNanos; + } + + /** @inheritDoc */ + public function getKind(): int + { + return $this->kind; + } + + /** @inheritDoc */ + public function getAttribute(string $key) + { + return $this->attributesBuilder[$key]; + } + + public function getStartEpochNanos(): int + { + return $this->startEpochNanos; + } + + public function getTotalRecordedLinks(): int + { + return $this->totalRecordedLinks; + } + + public function getTotalRecordedEvents(): int + { + return $this->totalRecordedEvents; + } + + public function getResource(): ResourceInfo + { + return $this->resource; + } +} diff --git a/vendor/open-telemetry/sdk/Trace/SpanBuilder.php b/vendor/open-telemetry/sdk/Trace/SpanBuilder.php new file mode 100644 index 000000000..2867c01c8 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SpanBuilder.php @@ -0,0 +1,191 @@ + */ + private array $links = []; + + private AttributesBuilderInterface $attributesBuilder; + private int $totalNumberOfLinksAdded = 0; + private int $startEpochNanos = 0; + + /** @param non-empty-string $spanName */ + public function __construct( + string $spanName, + InstrumentationScopeInterface $instrumentationScope, + TracerSharedState $tracerSharedState + ) { + $this->spanName = $spanName; + $this->instrumentationScope = $instrumentationScope; + $this->tracerSharedState = $tracerSharedState; + $this->attributesBuilder = $tracerSharedState->getSpanLimits()->getAttributesFactory()->builder(); + } + + /** @inheritDoc */ + public function setParent($context): API\SpanBuilderInterface + { + $this->parentContext = $context; + + return $this; + } + + /** @inheritDoc */ + public function addLink(API\SpanContextInterface $context, iterable $attributes = []): API\SpanBuilderInterface + { + if (!$context->isValid()) { + return $this; + } + + $this->totalNumberOfLinksAdded++; + + if (count($this->links) === $this->tracerSharedState->getSpanLimits()->getLinkCountLimit()) { + return $this; + } + + $this->links[] = new Link( + $context, + $this->tracerSharedState + ->getSpanLimits() + ->getLinkAttributesFactory() + ->builder($attributes) + ->build(), + ); + + return $this; + } + + /** @inheritDoc */ + public function setAttribute(string $key, $value): API\SpanBuilderInterface + { + $this->attributesBuilder[$key] = $value; + + return $this; + } + + /** @inheritDoc */ + public function setAttributes(iterable $attributes): API\SpanBuilderInterface + { + foreach ($attributes as $key => $value) { + $this->attributesBuilder[$key] = $value; + } + + return $this; + } + + /** + * @inheritDoc + * + * @psalm-param API\SpanKind::KIND_* $spanKind + */ + public function setSpanKind(int $spanKind): API\SpanBuilderInterface + { + $this->spanKind = $spanKind; + + return $this; + } + + /** @inheritDoc */ + public function setStartTimestamp(int $timestampNanos): API\SpanBuilderInterface + { + if (0 > $timestampNanos) { + return $this; + } + + $this->startEpochNanos = $timestampNanos; + + return $this; + } + + /** @inheritDoc */ + public function startSpan(): API\SpanInterface + { + $parentContext = Context::resolve($this->parentContext); + $parentSpan = Span::fromContext($parentContext); + $parentSpanContext = $parentSpan->getContext(); + + $spanId = $this->tracerSharedState->getIdGenerator()->generateSpanId(); + + if (!$parentSpanContext->isValid()) { + $traceId = $this->tracerSharedState->getIdGenerator()->generateTraceId(); + } else { + $traceId = $parentSpanContext->getTraceId(); + } + + $samplingResult = $this + ->tracerSharedState + ->getSampler() + ->shouldSample( + $parentContext, + $traceId, + $this->spanName, + $this->spanKind, + $this->attributesBuilder->build(), + $this->links, + ); + $samplingDecision = $samplingResult->getDecision(); + $samplingResultTraceState = $samplingResult->getTraceState(); + + $spanContext = API\SpanContext::create( + $traceId, + $spanId, + SamplingResult::RECORD_AND_SAMPLE === $samplingDecision ? API\TraceFlags::SAMPLED : API\TraceFlags::DEFAULT, + $samplingResultTraceState, + ); + + if (!in_array($samplingDecision, [SamplingResult::RECORD_AND_SAMPLE, SamplingResult::RECORD_ONLY], true)) { + return Span::wrap($spanContext); + } + + $attributesBuilder = clone $this->attributesBuilder; + foreach ($samplingResult->getAttributes() as $key => $value) { + $attributesBuilder[$key] = $value; + } + + return Span::startSpan( + $this->spanName, + $spanContext, + $this->instrumentationScope, + $this->spanKind, + $parentSpan, + $parentContext, + $this->tracerSharedState->getSpanLimits(), + $this->tracerSharedState->getSpanProcessor(), + $this->tracerSharedState->getResource(), + $attributesBuilder, + $this->links, + $this->totalNumberOfLinksAdded, + $this->startEpochNanos + ); + } +} diff --git a/vendor/open-telemetry/sdk/Trace/SpanConverterInterface.php b/vendor/open-telemetry/sdk/Trace/SpanConverterInterface.php new file mode 100644 index 000000000..40552e440 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SpanConverterInterface.php @@ -0,0 +1,10 @@ + */ + public function getEvents(): array; + + /** @return list */ + public function getLinks(): array; + + public function getEndEpochNanos(): int; + public function hasEnded(): bool; + public function getInstrumentationScope(): InstrumentationScopeInterface; + public function getResource(): ResourceInfo; + + /** @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/trace/sdk_exporters/non-otlp.md#dropped-events-count */ + public function getTotalDroppedEvents(): int; + + /** @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/trace/sdk_exporters/non-otlp.md#dropped-links-count */ + public function getTotalDroppedLinks(): int; +} diff --git a/vendor/open-telemetry/sdk/Trace/SpanExporter/AbstractDecorator.php b/vendor/open-telemetry/sdk/Trace/SpanExporter/AbstractDecorator.php new file mode 100644 index 000000000..42f49e815 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SpanExporter/AbstractDecorator.php @@ -0,0 +1,12 @@ +transport = $transport; + $this->setSpanConverter($converter ?? new FriendlySpanConverter()); + } + + public function export(iterable $batch, ?CancellationInterface $cancellation = null): FutureInterface + { + $payload = ''; + foreach ($batch as $span) { + try { + $payload .= json_encode( + $this->getSpanConverter()->convert([$span]), + JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT + ) . PHP_EOL; + } catch (JsonException $e) { + self::logWarning('Error converting span: ' . $e->getMessage()); + } + } + + return $this->transport->send($payload) + ->map(fn () => true) + ->catch(fn () => false); + } + + public function shutdown(?CancellationInterface $cancellation = null): bool + { + return $this->transport->shutdown(); + } + + public function forceFlush(?CancellationInterface $cancellation = null): bool + { + return $this->transport->forceFlush(); + } +} diff --git a/vendor/open-telemetry/sdk/Trace/SpanExporter/ConsoleSpanExporterFactory.php b/vendor/open-telemetry/sdk/Trace/SpanExporter/ConsoleSpanExporterFactory.php new file mode 100644 index 000000000..7e45fb549 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SpanExporter/ConsoleSpanExporterFactory.php @@ -0,0 +1,18 @@ +create('php://stdout', 'application/json'); + + return new ConsoleSpanExporter($transport); + } +} diff --git a/vendor/open-telemetry/sdk/Trace/SpanExporter/FriendlySpanConverter.php b/vendor/open-telemetry/sdk/Trace/SpanExporter/FriendlySpanConverter.php new file mode 100644 index 000000000..1f8178e10 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SpanExporter/FriendlySpanConverter.php @@ -0,0 +1,173 @@ +convertSpan($span); + } + + return $aggregate; + } + + /** + * friendlySpan does the heavy lifting converting a span into an array + * + * @param SpanDataInterface $span + * @return array + */ + private function convertSpan(SpanDataInterface $span): array + { + return [ + self::NAME_ATTR => $span->getName(), + self::CONTEXT_ATTR => $this->convertContext($span->getContext()), + self::RESOURCE_ATTR => $this->convertResource($span->getResource()), + self::PARENT_SPAN_ATTR => $this->covertParentContext($span->getParentContext()), + self::KIND_ATTR => $this->convertKind($span->getKind()), + self::START_ATTR => $span->getStartEpochNanos(), + self::END_ATTR => $span->getEndEpochNanos(), + self::ATTRIBUTES_ATTR => $this->convertAttributes($span->getAttributes()), + self::STATUS_ATTR => $this->covertStatus($span->getStatus()), + self::EVENTS_ATTR => $this->convertEvents($span->getEvents()), + self::LINKS_ATTR => $this->convertLinks($span->getLinks()), + ]; + } + + /** + * @param SpanContextInterface $context + * @return array + */ + private function convertContext(SpanContextInterface $context): array + { + return [ + self::TRACE_ID_ATTR => $context->getTraceId(), + self::SPAN_ID_ATTR => $context->getSpanId(), + self::TRACE_STATE_ATTR => (string) $context->getTraceState(), + ]; + } + + /** + * @param ResourceInfo $resource + * @return array + */ + private function convertResource(ResourceInfo $resource): array + { + return $resource->getAttributes()->toArray(); + } + + /** + * @param SpanContextInterface $context + * @return string + */ + private function covertParentContext(SpanContextInterface $context): string + { + return $context->isValid() ? $context->getSpanId() : ''; + } + + /** + * Translates SpanKind from its integer representation to a more human friendly string. + * + * @param int $kind + * @return string + */ + private function convertKind(int $kind): string + { + return array_flip( + (new ReflectionClass(SpanKind::class)) + ->getConstants() + )[$kind]; + } + + /** + * @param \OpenTelemetry\SDK\Common\Attribute\AttributesInterface $attributes + * @return array + */ + private function convertAttributes(AttributesInterface $attributes): array + { + return $attributes->toArray(); + } + + /** + * @param StatusDataInterface $status + * @return array + */ + private function covertStatus(StatusDataInterface $status): array + { + return [ + self::CODE_ATTR => $status->getCode(), + self::DESCRIPTION_ATTR => $status->getDescription(), + ]; + } + + /** + * @param array $events + * @return array + */ + private function convertEvents(array $events): array + { + $result = []; + + foreach ($events as $event) { + $result[] = [ + self::NAME_ATTR => $event->getName(), + self::TIMESTAMP_ATTR => $event->getEpochNanos(), + self::ATTRIBUTES_ATTR => $this->convertAttributes($event->getAttributes()), + ]; + } + + return $result; + } + + /** + * @param array $links + * @return array + */ + private function convertLinks(array $links): array + { + $result = []; + + foreach ($links as $link) { + $result[] = [ + self::CONTEXT_ATTR => $this->convertContext($link->getSpanContext()), + self::ATTRIBUTES_ATTR => $this->convertAttributes($link->getAttributes()), + ]; + } + + return $result; + } +} diff --git a/vendor/open-telemetry/sdk/Trace/SpanExporter/InMemoryExporter.php b/vendor/open-telemetry/sdk/Trace/SpanExporter/InMemoryExporter.php new file mode 100644 index 000000000..ebb022595 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SpanExporter/InMemoryExporter.php @@ -0,0 +1,40 @@ +storage = $storage ?? new ArrayObject(); + } + + protected function doExport(iterable $spans): bool + { + foreach ($spans as $span) { + $this->storage[] = $span; + } + + return true; + } + + public function getSpans(): array + { + return (array) $this->storage; + } + + public function getStorage(): ArrayObject + { + return $this->storage; + } +} diff --git a/vendor/open-telemetry/sdk/Trace/SpanExporter/InMemorySpanExporterFactory.php b/vendor/open-telemetry/sdk/Trace/SpanExporter/InMemorySpanExporterFactory.php new file mode 100644 index 000000000..c19686fac --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SpanExporter/InMemorySpanExporterFactory.php @@ -0,0 +1,15 @@ +setDecorated($decorated); + $this->setLogger($logger ?? new NullLogger()); + $this->setSpanConverter($converter ?? new FriendlySpanConverter()); + } + + protected function beforeExport(iterable $spans): iterable + { + return $spans; + } + + /** + * @param iterable $spans + * @param bool $exportSuccess + */ + protected function afterExport(iterable $spans, bool $exportSuccess): void + { + if ($exportSuccess) { + $this->log( + 'Status Success', + $this->getSpanConverter()->convert($spans), + LogLevel::INFO, + ); + } else { + $this->log( + 'Status Failed Retryable', + $this->getSpanConverter()->convert($spans), + LogLevel::ERROR, + ); + } + } +} diff --git a/vendor/open-telemetry/sdk/Trace/SpanExporter/LoggerExporter.php b/vendor/open-telemetry/sdk/Trace/SpanExporter/LoggerExporter.php new file mode 100644 index 000000000..1969a5426 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SpanExporter/LoggerExporter.php @@ -0,0 +1,96 @@ +setServiceName($serviceName); + $this->setLogger($logger ?? new NullLogger()); + $this->setDefaultLogLevel($defaultLogLevel ?? LogLevel::DEBUG); + $this->setSpanConverter($converter ?? new FriendlySpanConverter()); + $this->setGranularity($granularity); + } + + /** @inheritDoc */ + public function doExport(iterable $spans): bool + { + try { + $this->doLog($spans); + } catch (Throwable $t) { + return false; + } + + return true; + } + + /** + * @param string $serviceName + */ + private function setServiceName(string $serviceName): void + { + $this->serviceName = $serviceName; + } + + /** + * @param int $granularity + */ + public function setGranularity(int $granularity): void + { + $this->granularity = $granularity === self::GRANULARITY_SPAN + ? self::GRANULARITY_SPAN + : self::GRANULARITY_AGGREGATE; + } + + /** + * @param iterable $spans + */ + private function doLog(iterable $spans): void + { + if ($this->granularity === self::GRANULARITY_AGGREGATE) { + $this->log($this->serviceName, $this->getSpanConverter()->convert($spans)); + + return; + } + + foreach ($spans as $span) { + $this->log($this->serviceName, $this->getSpanConverter()->convert([$span])); + } + } +} diff --git a/vendor/open-telemetry/sdk/Trace/SpanExporter/NullSpanConverter.php b/vendor/open-telemetry/sdk/Trace/SpanExporter/NullSpanConverter.php new file mode 100644 index 000000000..1e55431a8 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SpanExporter/NullSpanConverter.php @@ -0,0 +1,15 @@ + $batch Batch of spans to export + * + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/specification/trace/sdk.md#exportbatch + * + * @psalm-return FutureInterface + */ + public function export(iterable $batch, ?CancellationInterface $cancellation = null): FutureInterface; + + /** @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/specification/trace/sdk.md#shutdown-2 */ + public function shutdown(?CancellationInterface $cancellation = null): bool; + + /** @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/specification/trace/sdk.md#forceflush-2 */ + public function forceFlush(?CancellationInterface $cancellation = null): bool; +} diff --git a/vendor/open-telemetry/sdk/Trace/SpanLimits.php b/vendor/open-telemetry/sdk/Trace/SpanLimits.php new file mode 100644 index 000000000..4b07649fc --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SpanLimits.php @@ -0,0 +1,67 @@ +attributesFactory; + } + + public function getEventAttributesFactory(): AttributesFactoryInterface + { + return $this->eventAttributesFactory; + } + + public function getLinkAttributesFactory(): AttributesFactoryInterface + { + return $this->linkAttributesFactory; + } + + /** @return int Maximum allowed span event count */ + public function getEventCountLimit(): int + { + return $this->eventCountLimit; + } + + /** @return int Maximum allowed span link count */ + public function getLinkCountLimit(): int + { + return $this->linkCountLimit; + } + + /** + * @internal Use {@see SpanLimitsBuilder} to create {@see SpanLimits} instance. + */ + public function __construct( + AttributesFactoryInterface $attributesFactory, + AttributesFactoryInterface $eventAttributesFactory, + AttributesFactoryInterface $linkAttributesFactory, + int $eventCountLimit, + int $linkCountLimit + ) { + $this->attributesFactory = $attributesFactory; + $this->eventAttributesFactory = $eventAttributesFactory; + $this->linkAttributesFactory = $linkAttributesFactory; + $this->eventCountLimit = $eventCountLimit; + $this->linkCountLimit = $linkCountLimit; + } +} diff --git a/vendor/open-telemetry/sdk/Trace/SpanLimitsBuilder.php b/vendor/open-telemetry/sdk/Trace/SpanLimitsBuilder.php new file mode 100644 index 000000000..11ed5a82b --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SpanLimitsBuilder.php @@ -0,0 +1,148 @@ +attributeCountLimit = $attributeCountLimit; + + return $this; + } + + /** + * @param int $attributeValueLengthLimit Maximum allowed attribute value length + */ + public function setAttributeValueLengthLimit(int $attributeValueLengthLimit): SpanLimitsBuilder + { + $this->attributeValueLengthLimit = $attributeValueLengthLimit; + + return $this; + } + + /** + * @param int $eventCountLimit Maximum allowed span event count + */ + public function setEventCountLimit(int $eventCountLimit): SpanLimitsBuilder + { + $this->eventCountLimit = $eventCountLimit; + + return $this; + } + + /** + * @param int $linkCountLimit Maximum allowed span link count + */ + public function setLinkCountLimit(int $linkCountLimit): SpanLimitsBuilder + { + $this->linkCountLimit = $linkCountLimit; + + return $this; + } + + /** + * @param int $attributePerEventCountLimit Maximum allowed attribute per span event count + */ + public function setAttributePerEventCountLimit(int $attributePerEventCountLimit): SpanLimitsBuilder + { + $this->attributePerEventCountLimit = $attributePerEventCountLimit; + + return $this; + } + + /** + * @param int $attributePerLinkCountLimit Maximum allowed attribute per span link count + */ + public function setAttributePerLinkCountLimit(int $attributePerLinkCountLimit): SpanLimitsBuilder + { + $this->attributePerLinkCountLimit = $attributePerLinkCountLimit; + + return $this; + } + + /** + * @param bool $retain whether general identity attributes should be retained + * + * @see https://github.com/open-telemetry/semantic-conventions/blob/main/docs/general/attributes.md#general-identity-attributes + */ + public function retainGeneralIdentityAttributes(bool $retain = true): SpanLimitsBuilder + { + $this->retainGeneralIdentityAttributes = $retain; + + return $this; + } + + /** + * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#span-limits + */ + public function build(): SpanLimits + { + $attributeCountLimit = $this->attributeCountLimit + ?: Configuration::getInt(Env::OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT, SpanLimits::DEFAULT_SPAN_ATTRIBUTE_COUNT_LIMIT); + $attributeValueLengthLimit = $this->attributeValueLengthLimit + ?: Configuration::getInt(Env::OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT, SpanLimits::DEFAULT_SPAN_ATTRIBUTE_LENGTH_LIMIT); + $eventCountLimit = $this->eventCountLimit + ?: Configuration::getInt(Env::OTEL_SPAN_EVENT_COUNT_LIMIT, SpanLimits::DEFAULT_SPAN_EVENT_COUNT_LIMIT); + $linkCountLimit = $this->linkCountLimit + ?: Configuration::getInt(Env::OTEL_SPAN_LINK_COUNT_LIMIT, SpanLimits::DEFAULT_SPAN_LINK_COUNT_LIMIT); + $attributePerEventCountLimit = $this->attributePerEventCountLimit + ?: Configuration::getInt(Env::OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT, SpanLimits::DEFAULT_EVENT_ATTRIBUTE_COUNT_LIMIT); + $attributePerLinkCountLimit = $this->attributePerLinkCountLimit + ?: Configuration::getInt(Env::OTEL_LINK_ATTRIBUTE_COUNT_LIMIT, SpanLimits::DEFAULT_LINK_ATTRIBUTE_COUNT_LIMIT); + + if ($attributeValueLengthLimit === PHP_INT_MAX) { + $attributeValueLengthLimit = null; + } + + $spanAttributesFactory = Attributes::factory($attributeCountLimit, $attributeValueLengthLimit); + + if (!$this->retainGeneralIdentityAttributes) { + $spanAttributesFactory = new FilteredAttributesFactory($spanAttributesFactory, [ + TraceAttributes::ENDUSER_ID, + TraceAttributes::ENDUSER_ROLE, + TraceAttributes::ENDUSER_SCOPE, + ]); + } + + return new SpanLimits( + $spanAttributesFactory, + Attributes::factory($attributePerEventCountLimit, $attributeValueLengthLimit), + Attributes::factory($attributePerLinkCountLimit, $attributeValueLengthLimit), + $eventCountLimit, + $linkCountLimit, + ); + } +} diff --git a/vendor/open-telemetry/sdk/Trace/SpanProcessor/BatchSpanProcessor.php b/vendor/open-telemetry/sdk/Trace/SpanProcessor/BatchSpanProcessor.php new file mode 100644 index 000000000..58032749e --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SpanProcessor/BatchSpanProcessor.php @@ -0,0 +1,290 @@ + 'batching']; + private const ATTRIBUTES_QUEUED = self::ATTRIBUTES_PROCESSOR + ['state' => 'queued']; + private const ATTRIBUTES_PENDING = self::ATTRIBUTES_PROCESSOR + ['state' => 'pending']; + private const ATTRIBUTES_PROCESSED = self::ATTRIBUTES_PROCESSOR + ['state' => 'processed']; + private const ATTRIBUTES_DROPPED = self::ATTRIBUTES_PROCESSOR + ['state' => 'dropped']; + private const ATTRIBUTES_FREE = self::ATTRIBUTES_PROCESSOR + ['state' => 'free']; + + private SpanExporterInterface $exporter; + private ClockInterface $clock; + private int $maxQueueSize; + private int $scheduledDelayNanos; + private int $maxExportBatchSize; + private bool $autoFlush; + private ContextInterface $exportContext; + + private ?int $nextScheduledRun = null; + private bool $running = false; + private int $dropped = 0; + private int $processed = 0; + private int $batchId = 0; + private int $queueSize = 0; + /** @var list */ + private array $batch = []; + /** @var SplQueue> */ + private SplQueue $queue; + /** @var SplQueue */ + private SplQueue $flush; + + private bool $closed = false; + + public function __construct( + SpanExporterInterface $exporter, + ClockInterface $clock, + int $maxQueueSize = self::DEFAULT_MAX_QUEUE_SIZE, + int $scheduledDelayMillis = self::DEFAULT_SCHEDULE_DELAY, + int $exportTimeoutMillis = self::DEFAULT_EXPORT_TIMEOUT, + int $maxExportBatchSize = self::DEFAULT_MAX_EXPORT_BATCH_SIZE, + bool $autoFlush = true, + ?MeterProviderInterface $meterProvider = null + ) { + if ($maxQueueSize <= 0) { + throw new InvalidArgumentException(sprintf('Maximum queue size (%d) must be greater than zero', $maxQueueSize)); + } + if ($scheduledDelayMillis <= 0) { + throw new InvalidArgumentException(sprintf('Scheduled delay (%d) must be greater than zero', $scheduledDelayMillis)); + } + if ($exportTimeoutMillis <= 0) { + throw new InvalidArgumentException(sprintf('Export timeout (%d) must be greater than zero', $exportTimeoutMillis)); + } + if ($maxExportBatchSize <= 0) { + throw new InvalidArgumentException(sprintf('Maximum export batch size (%d) must be greater than zero', $maxExportBatchSize)); + } + if ($maxExportBatchSize > $maxQueueSize) { + throw new InvalidArgumentException(sprintf('Maximum export batch size (%d) must be less than or equal to maximum queue size (%d)', $maxExportBatchSize, $maxQueueSize)); + } + + $this->exporter = $exporter; + $this->clock = $clock; + $this->maxQueueSize = $maxQueueSize; + $this->scheduledDelayNanos = $scheduledDelayMillis * 1_000_000; + $this->maxExportBatchSize = $maxExportBatchSize; + $this->autoFlush = $autoFlush; + + $this->exportContext = Context::getCurrent(); + $this->queue = new SplQueue(); + $this->flush = new SplQueue(); + + if ($meterProvider === null) { + return; + } + + $meter = $meterProvider->getMeter('io.opentelemetry.sdk'); + $meter + ->createObservableUpDownCounter( + 'otel.trace.span_processor.spans', + '{spans}', + 'The number of sampled spans received by the span processor', + ) + ->observe(function (ObserverInterface $observer): void { + $queued = $this->queue->count() * $this->maxExportBatchSize + count($this->batch); + $pending = $this->queueSize - $queued; + $processed = $this->processed; + $dropped = $this->dropped; + + $observer->observe($queued, self::ATTRIBUTES_QUEUED); + $observer->observe($pending, self::ATTRIBUTES_PENDING); + $observer->observe($processed, self::ATTRIBUTES_PROCESSED); + $observer->observe($dropped, self::ATTRIBUTES_DROPPED); + }); + $meter + ->createObservableUpDownCounter( + 'otel.trace.span_processor.queue.limit', + '{spans}', + 'The queue size limit', + ) + ->observe(function (ObserverInterface $observer): void { + $observer->observe($this->maxQueueSize, self::ATTRIBUTES_PROCESSOR); + }); + $meter + ->createObservableUpDownCounter( + 'otel.trace.span_processor.queue.usage', + '{spans}', + 'The current queue usage', + ) + ->observe(function (ObserverInterface $observer): void { + $queued = $this->queue->count() * $this->maxExportBatchSize + count($this->batch); + $pending = $this->queueSize - $queued; + $free = $this->maxQueueSize - $this->queueSize; + + $observer->observe($queued, self::ATTRIBUTES_QUEUED); + $observer->observe($pending, self::ATTRIBUTES_PENDING); + $observer->observe($free, self::ATTRIBUTES_FREE); + }); + } + + public function onStart(ReadWriteSpanInterface $span, ContextInterface $parentContext): void + { + } + + public function onEnd(ReadableSpanInterface $span): void + { + if ($this->closed) { + return; + } + if (!$span->getContext()->isSampled()) { + return; + } + + if ($this->queueSize === $this->maxQueueSize) { + $this->dropped++; + + return; + } + + $this->queueSize++; + $this->batch[] = $span->toSpanData(); + $this->nextScheduledRun ??= $this->clock->now() + $this->scheduledDelayNanos; + + if (count($this->batch) === $this->maxExportBatchSize) { + $this->enqueueBatch(); + } + if ($this->autoFlush) { + $this->flush(); + } + } + + public function forceFlush(?CancellationInterface $cancellation = null): bool + { + if ($this->closed) { + return false; + } + + return $this->flush(__FUNCTION__, $cancellation); + } + + public function shutdown(?CancellationInterface $cancellation = null): bool + { + if ($this->closed) { + return false; + } + + $this->closed = true; + + return $this->flush(__FUNCTION__, $cancellation); + } + + public static function builder(SpanExporterInterface $exporter): BatchSpanProcessorBuilder + { + return new BatchSpanProcessorBuilder($exporter); + } + + private function flush(?string $flushMethod = null, ?CancellationInterface $cancellation = null): bool + { + if ($flushMethod !== null) { + $flushId = $this->batchId + $this->queue->count() + (int) (bool) $this->batch; + $this->flush->enqueue([$flushId, $flushMethod, $cancellation, !$this->running, Context::getCurrent()]); + } + + if ($this->running) { + return false; + } + + $success = true; + $exception = null; + $this->running = true; + + try { + for (;;) { + while (!$this->flush->isEmpty() && $this->flush->bottom()[0] <= $this->batchId) { + [, $flushMethod, $cancellation, $propagateResult, $context] = $this->flush->dequeue(); + $scope = $context->activate(); + + try { + $result = $this->exporter->$flushMethod($cancellation); + if ($propagateResult) { + $success = $result; + } + } catch (Throwable $e) { + if ($propagateResult) { + $exception = $e; + } else { + self::logError(sprintf('Unhandled %s error', $flushMethod), ['exception' => $e]); + } + } finally { + $scope->detach(); + } + } + + if (!$this->shouldFlush()) { + break; + } + + if ($this->queue->isEmpty()) { + $this->enqueueBatch(); + } + $batchSize = count($this->queue->bottom()); + $this->batchId++; + $scope = $this->exportContext->activate(); + + try { + $this->exporter->export($this->queue->dequeue())->await(); + } catch (Throwable $e) { + self::logError('Unhandled export error', ['exception' => $e]); + } finally { + $this->processed += $batchSize; + $this->queueSize -= $batchSize; + $scope->detach(); + } + } + } finally { + $this->running = false; + } + + if ($exception !== null) { + throw $exception; + } + + return $success; + } + + private function shouldFlush(): bool + { + return !$this->flush->isEmpty() + || $this->autoFlush && !$this->queue->isEmpty() + || $this->autoFlush && $this->nextScheduledRun !== null && $this->clock->now() > $this->nextScheduledRun; + } + + private function enqueueBatch(): void + { + assert($this->batch !== []); + + $this->queue->enqueue($this->batch); + $this->batch = []; + $this->nextScheduledRun = null; + } +} diff --git a/vendor/open-telemetry/sdk/Trace/SpanProcessor/BatchSpanProcessorBuilder.php b/vendor/open-telemetry/sdk/Trace/SpanProcessor/BatchSpanProcessorBuilder.php new file mode 100644 index 000000000..8e81e7dd6 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SpanProcessor/BatchSpanProcessorBuilder.php @@ -0,0 +1,41 @@ +exporter = $exporter; + } + + public function setMeterProvider(MeterProviderInterface $meterProvider): self + { + $this->meterProvider = $meterProvider; + + return $this; + } + + public function build(): BatchSpanProcessor + { + return new BatchSpanProcessor( + $this->exporter, + ClockFactory::getDefault(), + BatchSpanProcessor::DEFAULT_MAX_QUEUE_SIZE, + BatchSpanProcessor::DEFAULT_SCHEDULE_DELAY, + BatchSpanProcessor::DEFAULT_EXPORT_TIMEOUT, + BatchSpanProcessor::DEFAULT_MAX_EXPORT_BATCH_SIZE, + true, + $this->meterProvider + ); + } +} diff --git a/vendor/open-telemetry/sdk/Trace/SpanProcessor/MultiSpanProcessor.php b/vendor/open-telemetry/sdk/Trace/SpanProcessor/MultiSpanProcessor.php new file mode 100644 index 000000000..e690791f2 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SpanProcessor/MultiSpanProcessor.php @@ -0,0 +1,79 @@ + */ + private array $processors = []; + + public function __construct(SpanProcessorInterface ...$spanProcessors) + { + foreach ($spanProcessors as $processor) { + $this->addSpanProcessor($processor); + } + } + + public function addSpanProcessor(SpanProcessorInterface $processor): void + { + $this->processors[] = $processor; + } + + /** @return list */ + public function getSpanProcessors(): array + { + return $this->processors; + } + + /** @inheritDoc */ + public function onStart(ReadWriteSpanInterface $span, ContextInterface $parentContext): void + { + foreach ($this->processors as $processor) { + $processor->onStart($span, $parentContext); + } + } + + /** @inheritDoc */ + public function onEnd(ReadableSpanInterface $span): void + { + foreach ($this->processors as $processor) { + $processor->onEnd($span); + } + } + + /** @inheritDoc */ + public function shutdown(?CancellationInterface $cancellation = null): bool + { + $result = true; + + foreach ($this->processors as $processor) { + $result = $result && $processor->shutdown(); + } + + return $result; + } + + /** @inheritDoc */ + public function forceFlush(?CancellationInterface $cancellation = null): bool + { + $result = true; + + foreach ($this->processors as $processor) { + $result = $result && $processor->forceFlush(); + } + + return $result; + } +} diff --git a/vendor/open-telemetry/sdk/Trace/SpanProcessor/NoopSpanProcessor.php b/vendor/open-telemetry/sdk/Trace/SpanProcessor/NoopSpanProcessor.php new file mode 100644 index 000000000..9c4d1eabe --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SpanProcessor/NoopSpanProcessor.php @@ -0,0 +1,47 @@ +forceFlush(); + } +} diff --git a/vendor/open-telemetry/sdk/Trace/SpanProcessor/SimpleSpanProcessor.php b/vendor/open-telemetry/sdk/Trace/SpanProcessor/SimpleSpanProcessor.php new file mode 100644 index 000000000..4e86e79ab --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SpanProcessor/SimpleSpanProcessor.php @@ -0,0 +1,120 @@ + */ + private SplQueue $queue; + + private bool $closed = false; + + public function __construct(SpanExporterInterface $exporter) + { + $this->exporter = $exporter; + + $this->exportContext = Context::getCurrent(); + $this->queue = new SplQueue(); + } + + public function onStart(ReadWriteSpanInterface $span, ContextInterface $parentContext): void + { + } + + public function onEnd(ReadableSpanInterface $span): void + { + if ($this->closed) { + return; + } + if (!$span->getContext()->isSampled()) { + return; + } + + $spanData = $span->toSpanData(); + $this->flush(fn () => $this->exporter->export([$spanData])->await(), 'export', false, $this->exportContext); + } + + public function forceFlush(?CancellationInterface $cancellation = null): bool + { + if ($this->closed) { + return false; + } + + return $this->flush(fn (): bool => $this->exporter->forceFlush($cancellation), __FUNCTION__, true, Context::getCurrent()); + } + + public function shutdown(?CancellationInterface $cancellation = null): bool + { + if ($this->closed) { + return false; + } + + $this->closed = true; + + return $this->flush(fn (): bool => $this->exporter->shutdown($cancellation), __FUNCTION__, true, Context::getCurrent()); + } + + private function flush(Closure $task, string $taskName, bool $propagateResult, ContextInterface $context): bool + { + $this->queue->enqueue([$task, $taskName, $propagateResult && !$this->running, $context]); + + if ($this->running) { + return false; + } + + $success = true; + $exception = null; + $this->running = true; + + try { + while (!$this->queue->isEmpty()) { + [$task, $taskName, $propagateResult, $context] = $this->queue->dequeue(); + $scope = $context->activate(); + + try { + $result = $task(); + if ($propagateResult) { + $success = $result; + } + } catch (Throwable $e) { + if ($propagateResult) { + $exception = $e; + } else { + self::logError(sprintf('Unhandled %s error', $taskName), ['exception' => $e]); + } + } finally { + $scope->detach(); + } + } + } finally { + $this->running = false; + } + + if ($exception !== null) { + throw $exception; + } + + return $success; + } +} diff --git a/vendor/open-telemetry/sdk/Trace/SpanProcessorFactory.php b/vendor/open-telemetry/sdk/Trace/SpanProcessorFactory.php new file mode 100644 index 000000000..39144cdf6 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/SpanProcessorFactory.php @@ -0,0 +1,48 @@ +code = $code; + $this->description = $description; + } + + /** @psalm-param API\StatusCode::STATUS_* $code */ + public static function create(string $code, ?string $description = null): self + { + if (empty($description)) { + switch ($code) { + case API\StatusCode::STATUS_UNSET: + return self::unset(); + case API\StatusCode::STATUS_ERROR: + return self::error(); + case API\StatusCode::STATUS_OK: + return self::ok(); + } + } + + // Ignore description for non Error statuses. + if (API\StatusCode::STATUS_ERROR !== $code) { + $description = ''; + } + + return new self($code, $description); /** @phan-suppress-current-line PhanTypeMismatchArgumentNullable */ + } + + public static function ok(): self + { + if (null === self::$ok) { + self::$ok = new self(API\StatusCode::STATUS_OK, ''); + } + + return self::$ok; + } + + public static function error(): self + { + if (null === self::$error) { + self::$error = new self(API\StatusCode::STATUS_ERROR, ''); + } + + return self::$error; + } + + public static function unset(): self + { + if (null === self::$unset) { + self::$unset = new self(API\StatusCode::STATUS_UNSET, ''); + } + + return self::$unset; + } + + public function getCode(): string + { + return $this->code; + } + + public function getDescription(): string + { + return $this->description; + } +} diff --git a/vendor/open-telemetry/sdk/Trace/StatusDataInterface.php b/vendor/open-telemetry/sdk/Trace/StatusDataInterface.php new file mode 100644 index 000000000..973d2b519 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/StatusDataInterface.php @@ -0,0 +1,18 @@ +tracerSharedState = $tracerSharedState; + $this->instrumentationScope = $instrumentationScope; + } + + /** @inheritDoc */ + public function spanBuilder(string $spanName): API\SpanBuilderInterface + { + if (ctype_space($spanName)) { + $spanName = self::FALLBACK_SPAN_NAME; + } + + if ($this->tracerSharedState->hasShutdown()) { + return new API\NoopSpanBuilder(Context::storage()); + } + + return new SpanBuilder( + $spanName, + $this->instrumentationScope, + $this->tracerSharedState, + ); + } + + public function getInstrumentationScope(): InstrumentationScopeInterface + { + return $this->instrumentationScope; + } +} diff --git a/vendor/open-telemetry/sdk/Trace/TracerProvider.php b/vendor/open-telemetry/sdk/Trace/TracerProvider.php new file mode 100644 index 000000000..fdae4aea2 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/TracerProvider.php @@ -0,0 +1,99 @@ +|SpanProcessorInterface|null $spanProcessors */ + public function __construct( + $spanProcessors = [], + SamplerInterface $sampler = null, + ResourceInfo $resource = null, + SpanLimits $spanLimits = null, + IdGeneratorInterface $idGenerator = null, + ?InstrumentationScopeFactoryInterface $instrumentationScopeFactory = null + ) { + if (null === $spanProcessors) { + $spanProcessors = []; + } + + $spanProcessors = is_array($spanProcessors) ? $spanProcessors : [$spanProcessors]; + $resource ??= ResourceInfoFactory::defaultResource(); + $sampler ??= new ParentBased(new AlwaysOnSampler()); + $idGenerator ??= new RandomIdGenerator(); + $spanLimits ??= (new SpanLimitsBuilder())->build(); + + $this->tracerSharedState = new TracerSharedState( + $idGenerator, + $resource, + $spanLimits, + $sampler, + $spanProcessors + ); + $this->instrumentationScopeFactory = $instrumentationScopeFactory ?? new InstrumentationScopeFactory(Attributes::factory()); + } + + public function forceFlush(?CancellationInterface $cancellation = null): bool + { + return $this->tracerSharedState->getSpanProcessor()->forceFlush($cancellation); + } + + /** + * @inheritDoc + */ + public function getTracer( + string $name, + ?string $version = null, + ?string $schemaUrl = null, + iterable $attributes = [] + ): API\TracerInterface { + if ($this->tracerSharedState->hasShutdown()) { + return NoopTracer::getInstance(); + } + + return new Tracer( + $this->tracerSharedState, + $this->instrumentationScopeFactory->create($name, $version, $schemaUrl, $attributes), + ); + } + + public function getSampler(): SamplerInterface + { + return $this->tracerSharedState->getSampler(); + } + + /** + * Returns `false` is the provider is already shutdown, otherwise `true`. + */ + public function shutdown(?CancellationInterface $cancellation = null): bool + { + if ($this->tracerSharedState->hasShutdown()) { + return true; + } + + return $this->tracerSharedState->shutdown($cancellation); + } + + public static function builder(): TracerProviderBuilder + { + return new TracerProviderBuilder(); + } +} diff --git a/vendor/open-telemetry/sdk/Trace/TracerProviderBuilder.php b/vendor/open-telemetry/sdk/Trace/TracerProviderBuilder.php new file mode 100644 index 000000000..8dcfdc700 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/TracerProviderBuilder.php @@ -0,0 +1,45 @@ + + private ?array $spanProcessors = []; + private ?ResourceInfo $resource = null; + private ?SamplerInterface $sampler = null; + + public function addSpanProcessor(SpanProcessorInterface $spanProcessor): self + { + $this->spanProcessors[] = $spanProcessor; + + return $this; + } + + public function setResource(ResourceInfo $resource): self + { + $this->resource = $resource; + + return $this; + } + + public function setSampler(SamplerInterface $sampler): self + { + $this->sampler = $sampler; + + return $this; + } + + public function build(): TracerProviderInterface + { + return new TracerProvider( + $this->spanProcessors, + $this->sampler, + $this->resource, + ); + } +} diff --git a/vendor/open-telemetry/sdk/Trace/TracerProviderFactory.php b/vendor/open-telemetry/sdk/Trace/TracerProviderFactory.php new file mode 100644 index 000000000..a545319b6 --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/TracerProviderFactory.php @@ -0,0 +1,60 @@ +exporterFactory = $exporterFactory ?: new ExporterFactory(); + $this->samplerFactory = $samplerFactory ?: new SamplerFactory(); + $this->spanProcessorFactory = $spanProcessorFactory ?: new SpanProcessorFactory(); + } + + public function create(): TracerProviderInterface + { + if (Sdk::isDisabled()) { + return new NoopTracerProvider(); + } + + try { + $exporter = $this->exporterFactory->create(); + } catch (\Throwable $t) { + self::logWarning('Unable to create exporter', ['exception' => $t]); + $exporter = null; + } + + try { + $sampler = $this->samplerFactory->create(); + } catch (\Throwable $t) { + self::logWarning('Unable to create sampler', ['exception' => $t]); + $sampler = null; + } + + try { + $spanProcessor = $this->spanProcessorFactory->create($exporter); + } catch (\Throwable $t) { + self::logWarning('Unable to create span processor', ['exception' => $t]); + $spanProcessor = null; + } + + return new TracerProvider( + $spanProcessor, + $sampler, + ); + } +} diff --git a/vendor/open-telemetry/sdk/Trace/TracerProviderInterface.php b/vendor/open-telemetry/sdk/Trace/TracerProviderInterface.php new file mode 100644 index 000000000..d61c1ea8f --- /dev/null +++ b/vendor/open-telemetry/sdk/Trace/TracerProviderInterface.php @@ -0,0 +1,15 @@ +idGenerator = $idGenerator; + $this->resource = $resource; + $this->spanLimits = $spanLimits; + $this->sampler = $sampler; + + switch (count($spanProcessors)) { + case 0: + $this->spanProcessor = NoopSpanProcessor::getInstance(); + + break; + case 1: + $this->spanProcessor = $spanProcessors[0]; + + break; + default: + $this->spanProcessor = new MultiSpanProcessor(...$spanProcessors); + + break; + } + } + + public function hasShutdown(): bool + { + return null !== $this->shutdownResult; + } + + public function getIdGenerator(): IdGeneratorInterface + { + return $this->idGenerator; + } + + public function getResource(): ResourceInfo + { + return $this->resource; + } + + public function getSpanLimits(): SpanLimits + { + return $this->spanLimits; + } + + public function getSampler(): SamplerInterface + { + return $this->sampler; + } + + public function getSpanProcessor(): SpanProcessorInterface + { + return $this->spanProcessor; + } + + /** + * Returns `false` is the provider is already shutdown, otherwise `true`. + */ + public function shutdown(?CancellationInterface $cancellation = null): bool + { + return $this->shutdownResult ?? ($this->shutdownResult = $this->spanProcessor->shutdown($cancellation)); + } +} diff --git a/vendor/open-telemetry/sdk/_autoload.php b/vendor/open-telemetry/sdk/_autoload.php new file mode 100644 index 000000000..4e1de3450 --- /dev/null +++ b/vendor/open-telemetry/sdk/_autoload.php @@ -0,0 +1,5 @@ +