From 3dc6473c98c73e6b0732515ad428b6d4c663f427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=81ach?= Date: Fri, 5 Jan 2024 15:06:25 +0100 Subject: [PATCH] drop code related to unsupported features (#754) * drop code related to unsupported features * remove leftovers * additional removals --- docs/internal/internal-config.md | 17 - .../DatadogExporter.cs | 12 - .../AssemblyProcessor.cs | 1 - .../Datadog.Trace.MSBuild/DatadogLogger.cs | 9 - .../Agent/Payloads/CICodeCoveragePayload.cs | 6 +- .../Ci/Agent/Payloads/CITestCyclePayload.cs | 7 +- tracer/src/Datadog.Trace/Ci/CIVisibility.cs | 59 +-- .../Ci/Configuration/CIVisibilitySettings.cs | 30 +- .../DirectSubmissionLogger.cs | 105 ----- .../DirectSubmissionLoggerProvider.cs | 78 ---- .../DirectSubmission/Formatting/LogEntry.cs | 49 --- .../Formatting/LoggerLogFormatter.cs | 175 -------- .../IExternalScopeProvider.cs | 32 -- .../DirectSubmission/ILoggerFactory.cs | 24 -- .../DirectSubmission/LoggerDatadogLogEvent.cs | 27 -- .../LoggerFactoryConstructorIntegration.cs | 73 ---- .../LoggerFactoryIntegrationCommon.cs | 103 ----- .../AppenderCollectionIntegration.cs | 61 --- .../AppenderCollectionLegacyIntegration.cs | 62 --- .../DirectSubmissionLog4NetAppender.cs | 78 ---- .../DirectSubmissionLog4NetLegacyAppender.cs | 78 ---- .../DirectSubmission/ILoggingEventDuck.cs | 20 - .../DirectSubmission/ILoggingEventDuckBase.cs | 47 -- .../ILoggingEventLegacyDuck.cs | 20 - .../Log4Net/DirectSubmission/LevelDuck.cs | 21 - .../DirectSubmission/LevelDuckExtensions.cs | 40 -- .../Log4Net/DirectSubmission/Log4NetCommon.cs | 65 --- .../Log4NetDatadogLogEvent.cs | 30 -- .../DirectSubmission/Log4NetLogFormatter.cs | 92 ---- .../DirectSubmissionNLogLegacyTarget.cs | 80 ---- .../DirectSubmissionNLogTarget.cs | 83 ---- .../DirectSubmission/Formatting/LogEntry.cs | 30 -- .../Formatting/NLogDatadogLogEvent.cs | 28 -- .../Formatting/NLogLogFormatter.cs | 104 ----- ...etConfigurationForLoggerInstrumentation.cs | 59 --- .../NLog/DirectSubmission/NLogCommon.cs | 404 ------------------ .../NLog/DirectSubmission/NLogConstants.cs | 16 - .../Proxies/ILogEventInfoLegacyProxy.cs | 23 - .../Proxies/ILogEventInfoProxy.cs | 26 -- .../Proxies/ILogEventInfoProxyBase.cs | 42 -- .../ILoggingConfigurationLegacyProxy.cs | 37 -- .../Proxies/ILoggingConfigurationProxy.cs | 38 -- .../DirectSubmission/Proxies/ITargetProxy.cs | 23 - .../Proxies/ITargetWithContextBaseProxy.cs | 60 --- .../DirectSubmission/Proxies/LogLevelProxy.cs | 21 - .../MappedDiagnosticsContextLegacyProxy.cs | 24 -- ...pedDiagnosticsLogicalContextLegacyProxy.cs | 23 - .../Proxies/MappedDiagnosticsProxy.cs | 35 -- .../Pre43/ILoggingConfigurationPre43Proxy.cs | 34 -- .../Proxies/Pre43/ILoggingRuleProxy.cs | 38 -- .../Proxies/Pre43/ILoggingRulesListProxy.cs | 23 - .../Proxies/Pre43/ITargetListProxy.cs | 22 - .../DirectSubmissionSerilogSink.cs | 47 -- .../Formatting/DictionaryValueDuck.cs | 23 - .../Formatting/KeyValuePairObjectStruct.cs | 26 -- .../Formatting/KeyValuePairStringStruct.cs | 26 -- .../Formatting/LogEventPropertyDuck.cs | 27 -- .../Formatting/ScalarValueDuck.cs | 22 - .../Formatting/SequenceValueDuck.cs | 24 -- .../Formatting/SerilogLogFormatter.cs | 162 ------- .../Formatting/StructureValueDuck.cs | 29 -- .../Serilog/DirectSubmission/ILogEvent.cs | 50 --- .../DirectSubmission/ILoggerConfiguration.cs | 23 - .../DirectSubmission/LogEventLevelDuck.cs | 48 --- .../LoggerConfigurationInstrumentation.cs | 85 ---- .../DirectSubmission/MessageTemplateProxy.cs | 21 - .../SerilogDatadogLogEvent.cs | 28 -- .../ConfigurationKeys.DirectLogSubmission.cs | 86 ---- .../Configuration/ConfigurationKeys.cs | 63 --- .../Configuration/ImmutableTracerSettings.cs | 2 +- .../Configuration/TracerSettings.cs | 2 - .../InstrumentationDefinitions.g.cs | 22 +- .../InstrumentationDefinitions.g.cs | 22 +- .../InstrumentationDefinitions.g.cs | 22 +- .../InstrumentationDefinitions.g.cs | 22 +- .../HttpOverStreams/DatadogHttpClient.cs | 3 - .../TelemetryAgentHttpHeaderHelper.cs | 33 -- .../DirectLogSubmissionManager.cs | 18 +- .../DirectLogSubmissionSettings.cs | 134 ------ .../ImmutableDirectLogSubmissionSettings.cs | 126 ------ .../DirectSubmission/LogsTransportStrategy.cs | 32 -- .../DirectSubmission/Sink/DatadogSink.cs | 190 -------- .../Logging/DirectSubmission/Sink/ILogsApi.cs | 16 - .../Logging/DirectSubmission/Sink/LogsApi.cs | 163 ------- .../Sink/LogsApiHeaderNames.cs | 25 -- .../Sink/PeriodicBatching/BatchingSink.cs | 266 ------------ .../Sink/PeriodicBatching/CircuitBreaker.cs | 67 --- .../Sink/PeriodicBatching/CircuitStatus.cs | 16 - .../ConfigurationTelemetryCollector.cs | 181 -------- .../DependencyTelemetryCollector.cs | 114 ----- .../IntegrationTelemetryCollector.cs | 164 ------- .../DTOs/AppDependenciesLoadedPayload.cs | 21 - .../DTOs/AppIntegrationsChangedPayload.cs | 21 - .../Telemetry/DTOs/AppStartedPayload.cs | 32 -- .../DTOs/ApplicationTelemetryData.cs | 39 -- .../Telemetry/DTOs/ConfigTelemetryData.cs | 42 -- .../Telemetry/DTOs/DependencyTelemetryData.cs | 23 - .../Telemetry/DTOs/GenerateMetricsPayload.cs | 14 - .../Telemetry/DTOs/HostTelemetryData.cs | 26 -- .../Datadog.Trace/Telemetry/DTOs/IPayload.cs | 11 - .../DTOs/IntegrationTelemetryData.cs | 28 -- .../Telemetry/DTOs/TelemetryData.cs | 59 --- .../Telemetry/DTOs/TelemetryValue.cs | 21 - .../Telemetry/ITelemetryTransport.cs | 20 - .../Telemetry/TelemetryCircuitBreaker.cs | 72 ---- .../Telemetry/TelemetryConstants.cs | 23 - .../Telemetry/TelemetryController.cs | 237 ---------- .../Telemetry/TelemetryDataBuilder.cs | 126 ------ .../Telemetry/TelemetryFactory.cs | 31 +- .../Telemetry/TelemetryHttpHeaderNames.cs | 34 -- .../Telemetry/TelemetryPushResult.cs | 17 - .../Telemetry/TelemetryRequestTypes.cs | 18 - .../Telemetry/TelemetrySettings.cs | 121 ------ .../Transports/JsonTelemetryTransport.cs | 95 ---- .../Transports/TelemetryTransportFactory.cs | 27 -- .../Transports/TelemetryTransportStrategy.cs | 57 --- .../AWS/AwsSqsTests.cs | 3 - .../AdoNet/FakeCommandTests.cs | 3 - .../AdoNet/MicrosoftDataSqlClientTests.cs | 5 - .../AdoNet/MicrosoftDataSqliteTests.cs | 5 - .../AdoNet/MySqlCommandTests.cs | 5 - .../AdoNet/MySqlConnectorTests.cs | 5 - .../AdoNet/NpgsqlCommandTests.cs | 5 - .../AdoNet/SqlCommand20Tests.cs | 5 - .../AdoNet/SystemDataSqlClientTests.cs | 5 - .../AdoNet/SystemDataSqliteTests.cs | 5 - .../AerospikeTests.cs | 3 - .../CI/MsTestV2Tests.cs | 337 --------------- .../CI/NUnitTests.cs | 374 ---------------- .../CI/XUnitTests.cs | 356 --------------- .../CosmosTests.cs | 2 - .../Couchbase3Tests.cs | 2 - .../CouchbaseTests.cs | 2 - .../Elasticsearch5Tests.cs | 4 - .../Elasticsearch6Tests.cs | 4 - .../Elasticsearch7Tests.cs | 4 - .../GraphQLTests.cs | 3 - .../GrpcTests.cs | 6 - .../Helpers/TelemetryHelper.cs | 153 ------- .../HttpMessageHandlerTests.cs | 11 - .../ILoggerTests.cs | 46 +- .../KafkaTests.cs | 3 - .../Log4NetTests.cs | 65 +-- .../MongoDbTests.cs | 3 - .../MsmqTests.cs | 2 - .../NLogTests.cs | 63 +-- .../RabbitMQTests.cs | 2 - .../SerilogTests.cs | 63 +-- .../ServiceStackRedisTests.cs | 3 - .../StackExchangeRedisTests.cs | 5 - .../TelemetryTests.cs | 175 -------- .../TraceAnnotationsTests.cs | 9 - .../TransportTests.cs | 3 - .../WcfTests.cs | 4 - .../WebRequest20Tests.cs | 4 - .../WebRequestTests.cs | 12 - .../ILogger/DirectSubmissionLoggerTests.cs | 147 ------- .../Logging/ILogger/ILoggerDuckTypingTests.cs | 242 ----------- .../ILogger/LoggerLogFormatterTests.cs | 117 ----- .../DirectSubmissionLog4NetAppenderTests.cs | 121 ------ .../Logging/Log4Net/Log4NetDuckTypingTests.cs | 42 -- .../Logging/Log4Net/Log4NetHelper.cs | 56 --- .../Log4Net/Log4NetLogFormatterTests.cs | 75 ---- .../NLog/DirectSubmissionNLogTargetTests.cs | 124 ------ .../Logging/NLog/NLogDuckTypingTests.cs | 273 ------------ .../Logging/NLog/NLogHelper.cs | 72 ---- .../Logging/NLog/NLogLogFormatterTests.cs | 81 ---- .../DirectSubmissionSerilogSinkTests.cs | 89 ---- .../Logging/Serilog/SerilogDuckTypingTests.cs | 213 --------- .../Logging/Serilog/SerilogHelper.cs | 55 --- .../Serilog/SerilogLogFormatterTests.cs | 66 --- .../TelemetryTransportTests.cs | 128 ------ .../EnvironmentHelper.cs | 5 - .../LogSettingsHelper.cs | 38 -- .../MockLogsIntake.cs | 259 ----------- .../MockTelemetryAgent.cs | 228 ---------- .../MockTracerAgent.cs | 170 ++------ .../Datadog.Trace.TestHelpers/TestHelper.cs | 22 - .../Datadog.Trace.Tests.csproj | 1 - .../DirectLogSubmissionSettingsTests.cs | 101 ----- ...DirectSubmissionLogLevelExtensionsTests.cs | 72 ---- .../Formatting/EventIdHashTests.cs | 30 -- .../Formatting/LogFormatterTests.cs | 221 ---------- ...mutableDirectLogSubmissionSettingsTests.cs | 245 ----------- .../DirectSubmission/Sink/DatadogSinkTests.cs | 284 ------------ .../DirectSubmission/Sink/LogsApiTests.cs | 226 ---------- .../PeriodicBatching/BatchingSinkTests.cs | 218 ---------- .../BoundedConcurrentQueueTests.cs | 60 --- .../PeriodicBatching/CircuitBreakerTests.cs | 128 ------ .../MockLogsIntakeTests.cs | 93 ---- .../CallTargetInvokerTelemetryTests.cs | 141 ------ .../ConfigurationTelemetryCollectorTests.cs | 203 --------- .../DependencyTelemetryCollectorTests.cs | 143 ------- .../IntegrationTelemetryCollectorTests.cs | 184 -------- .../Telemetry/TelemetryCircuitBreakerTests.cs | 122 ------ .../Telemetry/TelemetryControllerTests.cs | 183 -------- .../Telemetry/TelemetryDataBuilderTests.cs | 149 ------- .../Telemetry/TelemetrySettingsTests.cs | 243 ----------- .../Transports/JsonTelemetryTransportTests.cs | 92 ---- .../Telemetry/telemetry_data.json | 60 --- .../Util/ModuleInitializer.cs | 21 - 201 files changed, 81 insertions(+), 13870 deletions(-) delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/DirectSubmissionLogger.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/DirectSubmissionLoggerProvider.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/Formatting/LogEntry.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/Formatting/LoggerLogFormatter.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/IExternalScopeProvider.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/ILoggerFactory.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/LoggerDatadogLogEvent.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/LoggerFactoryConstructorIntegration.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/LoggerFactoryIntegrationCommon.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/AppenderCollectionIntegration.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/AppenderCollectionLegacyIntegration.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/DirectSubmissionLog4NetAppender.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/DirectSubmissionLog4NetLegacyAppender.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/ILoggingEventDuck.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/ILoggingEventDuckBase.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/ILoggingEventLegacyDuck.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/LevelDuck.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/LevelDuckExtensions.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/Log4NetCommon.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/Log4NetDatadogLogEvent.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/Log4NetLogFormatter.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/DirectSubmissionNLogLegacyTarget.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/DirectSubmissionNLogTarget.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Formatting/LogEntry.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Formatting/NLogDatadogLogEvent.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Formatting/NLogLogFormatter.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/LogFactoryGetConfigurationForLoggerInstrumentation.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/NLogCommon.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/NLogConstants.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILogEventInfoLegacyProxy.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILogEventInfoProxy.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILogEventInfoProxyBase.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILoggingConfigurationLegacyProxy.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILoggingConfigurationProxy.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ITargetProxy.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ITargetWithContextBaseProxy.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/LogLevelProxy.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/MappedDiagnosticsContextLegacyProxy.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/MappedDiagnosticsLogicalContextLegacyProxy.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/MappedDiagnosticsProxy.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/Pre43/ILoggingConfigurationPre43Proxy.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/Pre43/ILoggingRuleProxy.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/Pre43/ILoggingRulesListProxy.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/Pre43/ITargetListProxy.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/DirectSubmissionSerilogSink.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/DictionaryValueDuck.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/KeyValuePairObjectStruct.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/KeyValuePairStringStruct.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/LogEventPropertyDuck.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/ScalarValueDuck.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/SequenceValueDuck.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/SerilogLogFormatter.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/StructureValueDuck.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/ILogEvent.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/ILoggerConfiguration.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/LogEventLevelDuck.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/LoggerConfigurationInstrumentation.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/MessageTemplateProxy.cs delete mode 100644 tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/SerilogDatadogLogEvent.cs delete mode 100644 tracer/src/Datadog.Trace/Configuration/ConfigurationKeys.DirectLogSubmission.cs delete mode 100644 tracer/src/Datadog.Trace/HttpOverStreams/TelemetryAgentHttpHeaderHelper.cs delete mode 100644 tracer/src/Datadog.Trace/Logging/DirectSubmission/LogsTransportStrategy.cs delete mode 100644 tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/DatadogSink.cs delete mode 100644 tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/ILogsApi.cs delete mode 100644 tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/LogsApi.cs delete mode 100644 tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/LogsApiHeaderNames.cs delete mode 100644 tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/PeriodicBatching/BatchingSink.cs delete mode 100644 tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/PeriodicBatching/CircuitBreaker.cs delete mode 100644 tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/PeriodicBatching/CircuitStatus.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/Collectors/ConfigurationTelemetryCollector.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/Collectors/DependencyTelemetryCollector.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/Collectors/IntegrationTelemetryCollector.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/DTOs/AppDependenciesLoadedPayload.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/DTOs/AppIntegrationsChangedPayload.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/DTOs/AppStartedPayload.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/DTOs/ApplicationTelemetryData.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/DTOs/ConfigTelemetryData.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/DTOs/DependencyTelemetryData.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/DTOs/GenerateMetricsPayload.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/DTOs/HostTelemetryData.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/DTOs/IPayload.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/DTOs/IntegrationTelemetryData.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/DTOs/TelemetryData.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/DTOs/TelemetryValue.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/ITelemetryTransport.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/TelemetryCircuitBreaker.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/TelemetryConstants.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/TelemetryController.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/TelemetryDataBuilder.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/TelemetryHttpHeaderNames.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/TelemetryPushResult.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/TelemetryRequestTypes.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/TelemetrySettings.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/Transports/JsonTelemetryTransport.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/Transports/TelemetryTransportFactory.cs delete mode 100644 tracer/src/Datadog.Trace/Telemetry/Transports/TelemetryTransportStrategy.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CI/MsTestV2Tests.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CI/NUnitTests.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CI/XUnitTests.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Helpers/TelemetryHelper.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/TelemetryTests.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/ILogger/DirectSubmissionLoggerTests.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/ILogger/ILoggerDuckTypingTests.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/ILogger/LoggerLogFormatterTests.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Log4Net/DirectSubmissionLog4NetAppenderTests.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Log4Net/Log4NetDuckTypingTests.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Log4Net/Log4NetHelper.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Log4Net/Log4NetLogFormatterTests.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/NLog/DirectSubmissionNLogTargetTests.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/NLog/NLogDuckTypingTests.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/NLog/NLogHelper.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/NLog/NLogLogFormatterTests.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Serilog/DirectSubmissionSerilogSinkTests.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Serilog/SerilogDuckTypingTests.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Serilog/SerilogHelper.cs delete mode 100644 tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Serilog/SerilogLogFormatterTests.cs delete mode 100644 tracer/test/Datadog.Trace.IntegrationTests/TelemetryTransportTests.cs delete mode 100644 tracer/test/Datadog.Trace.TestHelpers/LogSettingsHelper.cs delete mode 100644 tracer/test/Datadog.Trace.TestHelpers/MockLogsIntake.cs delete mode 100644 tracer/test/Datadog.Trace.TestHelpers/MockTelemetryAgent.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/DirectLogSubmissionSettingsTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/DirectSubmissionLogLevelExtensionsTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Formatting/EventIdHashTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Formatting/LogFormatterTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/ImmutableDirectLogSubmissionSettingsTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/DatadogSinkTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/LogsApiTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/PeriodicBatching/BatchingSinkTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/PeriodicBatching/BoundedConcurrentQueueTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/PeriodicBatching/CircuitBreakerTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/MockLogsIntakeTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Telemetry/CallTargetInvokerTelemetryTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Telemetry/Collectors/ConfigurationTelemetryCollectorTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Telemetry/Collectors/DependencyTelemetryCollectorTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Telemetry/Collectors/IntegrationTelemetryCollectorTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Telemetry/TelemetryCircuitBreakerTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Telemetry/TelemetryControllerTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Telemetry/TelemetryDataBuilderTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Telemetry/TelemetrySettingsTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Telemetry/Transports/JsonTelemetryTransportTests.cs delete mode 100644 tracer/test/Datadog.Trace.Tests/Telemetry/telemetry_data.json delete mode 100644 tracer/test/Datadog.Trace.Tests/Util/ModuleInitializer.cs diff --git a/docs/internal/internal-config.md b/docs/internal/internal-config.md index 4260fed8d..5dc3483fb 100644 --- a/docs/internal/internal-config.md +++ b/docs/internal/internal-config.md @@ -13,15 +13,6 @@ These settings should be never used by the users. | `SIGNALFX_CONVENTION` | Sets the semantic and trace id conventions for the tracer. Available values are: `Datadog` (64bit trace id), `OpenTelemetry` (128 bit trace id). | `OpenTelemetry` | | `SIGNALFX_DUMP_ILREWRITE_ENABLED` | Allows the profiler to dump the IL original code and modification to the log. | `false` | | `SIGNALFX_EXPORTER` | The exporter to be used. The Tracer uses it to encode and dispatch traces. Available values are: `DatadogAgent`, `Zipkin`. | `Zipkin` | -| `SIGNALFX_LOGS_DIRECT_SUBMISSION_INTEGRATIONS` | Configuration key for a list of direct log submission integrations to enable. Only selected integrations are enabled for direct log submission. Supports multiple values separated with semi-colons. Valid values are `ILogger`, `Serilog`, `Log4Net`, `NLog` | `` | -| `SIGNALFX_LOGS_DIRECT_SUBMISSION_HOST` | Configuration key for the name of the originating host for direct logs submission. | `` | -| `SIGNALFX_LOGS_DIRECT_SUBMISSION_SOURCE` | Configuration key for the originating source for direct logs submission. | `csharp` | -| `SIGNALFX_LOGS_DIRECT_SUBMISSION_TAGS` | Configuration key for a list of tags to be applied globally to all logs directly submitted. Supports multiple key key-value pairs which are comma-separated, and for which the key and value are colon-separated. For example Key1:Value1, Key2:Value2 | `` | -| `SIGNALFX_LOGS_DIRECT_SUBMISSION_URL` | Configuration key for the url to send logs to. | `https://http-intake.logs.datadoghq.com:443` | -| `SIGNALFX_LOGS_DIRECT_SUBMISSION_MINIMUM_LEVEL` | Configuration key for the minimum level logs should have to be sent to the intake. Should be one of `Verbose`,`Debug`,`Information`,`Warning`,`Error`,`Fatal` | `Information` | -| `SIGNALFX_LOGS_DIRECT_SUBMISSION_MAX_BATCH_SIZE` | Configuration key for the maximum number of logs to send at one time | `1000` | -| `SIGNALFX_LOGS_DIRECT_SUBMISSION_MAX_QUEUE_SIZE` | Configuration key for the maximum number of logs to hold in internal queue at any one time | `100000` | -| `SIGNALFX_LOGS_DIRECT_SUBMISSION_BATCH_PERIOD_SECONDS` | Configuration key for the time in seconds to wait between checking for batches | `2` | | `SIGNALFX_PROFILER_MEMORY_ENABLED` | Enable to activate memory profiling. | `false` | | `SIGNALFX_PROFILER_MAX_MEMORY_SAMPLES_PER_MINUTE` | Configuratoin key for the maximum number of memory samples gathered per minute. | `200` | `SIGNALFX_PROFILER_EXPORT_INTERVAL` | Profiling exporter interval in milliseconds. It defines how often the profiling data is sent to the collector. If the CPU profiling is enabled this value will automatically be set to match `SIGNALFX_PROFILER_CALL_STACK_INTERVAL`. | `10000` | @@ -32,12 +23,6 @@ These settings should be never used by the users. |-|-|-| | `SIGNALFX_AGENT_HOST` | The Agent host where the tracer can send traces. | | | `SIGNALFX_APM_RECEIVER_PORT` | The port for Trace Agent binding. | `8126` | -| `SIGNALFX_CIVISIBILITY_AGENTLESS_ENABLED` | Enable to activate Agentless in CI Visibility. | `false` | -| `SIGNALFX_CIVISIBILITY_AGENTLESS_URL` | Configuration key for setting the agentless url endpoint. | | -| `SIGNALFX_CIVISIBILITY_CODE_COVERAGE_ENABLED` | Configuration key for enabling or disabling Code Coverage in CI Visibility. | `false` | -| `SIGNALFX_CIVISIBILITY_CODE_COVERAGE_SNK_FILEPATH` | Configuration key for re-signing assemblies after the Code Coverage modification. | | -| `SIGNALFX_CIVISIBILITY_ENABLED` | Enable to activate CI Visibility. | `false` | -| `SIGNALFX_CIVISIBILITY_LOGS_ENABLED` | Enable to activate Logs direct submission. | `false` | | `SIGNALFX_DOGSTATSD_ARGS` | Comma-separated list of arguments to be passed to the DogStatsD process. | | | `SIGNALFX_DOGSTATSD_PATH` | The DogStatsD path for when a standalone instance needs to be started. | | | `SIGNALFX_DOGSTATSD_PIPE_NAME` | The named pipe that DogStatsD binds to. | | @@ -67,8 +52,6 @@ These settings should be never used by the users. | `SIGNALFX_TRACE_TRANSPORT` | Overrides the transport to use for communicating with the trace agent. Available values are: `datagod-tcp`, `datadog-named-pipes`. | | | `SIGNALFX_AAS_ENABLE_CUSTOM_TRACING` | Used to force the loader to start the tracer agent (in case automatic instrumentation is disabled). Used in contexts where the user cannot manage agent processes, such as Azure App Services. | | | `SIGNALFX_AAS_ENABLE_CUSTOM_METRICS` | Used to force the loader to start dogstatsd (in case automatic instrumentation is disabled). Used in contexts where the user cannot manage agent processes, such as Azure App Services. | | -| `SIGNALFX_INSTRUMENTATION_TELEMETRY_ENABLED` | Used to enable internal telemetry. | `false` | -| `SIGNALFX_TRACE_TELEMETRY_URL` | Sets the telemetry URL where the tracer sends telemetry. | | | `SIGNALFX_SITE` | Sets the default destination site. | | | `SIGNALFX_LOG_LEVEL` | Sets the log level for serverless. | | | `_SIGNALFX_EXTENSION_PATH` | Sets the lambda extension path. | | diff --git a/tracer/src/Datadog.Trace.BenchmarkDotNet/DatadogExporter.cs b/tracer/src/Datadog.Trace.BenchmarkDotNet/DatadogExporter.cs index eccde2eaa..7eefae01e 100644 --- a/tracer/src/Datadog.Trace.BenchmarkDotNet/DatadogExporter.cs +++ b/tracer/src/Datadog.Trace.BenchmarkDotNet/DatadogExporter.cs @@ -29,18 +29,6 @@ public class DatadogExporter : IExporter private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(typeof(DatadogExporter)); - static DatadogExporter() - { - try - { - Environment.SetEnvironmentVariable(Configuration.ConfigurationKeys.CIVisibility.Enabled, "1", EnvironmentVariableTarget.Process); - } - catch - { - // . - } - } - /// public string Name => nameof(DatadogExporter); diff --git a/tracer/src/Datadog.Trace.Coverage.collector/AssemblyProcessor.cs b/tracer/src/Datadog.Trace.Coverage.collector/AssemblyProcessor.cs index 00d4488f5..f984fe79f 100644 --- a/tracer/src/Datadog.Trace.Coverage.collector/AssemblyProcessor.cs +++ b/tracer/src/Datadog.Trace.Coverage.collector/AssemblyProcessor.cs @@ -107,7 +107,6 @@ public void Process() } else if (tracerTarget == TracerTarget.Net461) { - _logger.Debug($"Assembly: {FilePath}, is a net461 signed assembly, a .snk file is required ({Configuration.ConfigurationKeys.CIVisibility.CodeCoverageSnkFile} environment variable)."); return; } } diff --git a/tracer/src/Datadog.Trace.MSBuild/DatadogLogger.cs b/tracer/src/Datadog.Trace.MSBuild/DatadogLogger.cs index d9c69c3a5..1c0d26825 100644 --- a/tracer/src/Datadog.Trace.MSBuild/DatadogLogger.cs +++ b/tracer/src/Datadog.Trace.MSBuild/DatadogLogger.cs @@ -35,15 +35,6 @@ public class DatadogLogger : INodeLogger static DatadogLogger() { - try - { - Environment.SetEnvironmentVariable(Configuration.ConfigurationKeys.CIVisibility.Enabled, "1", EnvironmentVariableTarget.Process); - } - catch - { - // . - } - CIVisibility.Initialize(); } diff --git a/tracer/src/Datadog.Trace/Ci/Agent/Payloads/CICodeCoveragePayload.cs b/tracer/src/Datadog.Trace/Ci/Agent/Payloads/CICodeCoveragePayload.cs index 12f89eb17..62fb18ab6 100644 --- a/tracer/src/Datadog.Trace/Ci/Agent/Payloads/CICodeCoveragePayload.cs +++ b/tracer/src/Datadog.Trace/Ci/Agent/Payloads/CICodeCoveragePayload.cs @@ -21,16 +21,14 @@ public CICodeCoveragePayload(int maxItemsPerPayload = DefaultMaxItemsPerPayload, if (!string.IsNullOrWhiteSpace(agentlessUrl)) { var builder = new UriBuilder(agentlessUrl); - builder.Path = "api/v2/citestcov"; Url = builder.Uri; } else { Url = new UriBuilder( scheme: "https", - host: "event-platform-intake." + CIVisibility.Settings.Site, - port: 443, - pathValue: "api/v2/citestcov").Uri; + host: CIVisibility.Settings.Site, + portNumber: 443).Uri; } // We call reset here to add the dummy event diff --git a/tracer/src/Datadog.Trace/Ci/Agent/Payloads/CITestCyclePayload.cs b/tracer/src/Datadog.Trace/Ci/Agent/Payloads/CITestCyclePayload.cs index a61334c9f..28c18fac7 100644 --- a/tracer/src/Datadog.Trace/Ci/Agent/Payloads/CITestCyclePayload.cs +++ b/tracer/src/Datadog.Trace/Ci/Agent/Payloads/CITestCyclePayload.cs @@ -18,16 +18,15 @@ public CITestCyclePayload(IFormatterResolver formatterResolver = null) if (!string.IsNullOrWhiteSpace(agentlessUrl)) { var builder = new UriBuilder(agentlessUrl); - builder.Path = "api/v2/citestcycle"; Url = builder.Uri; } else { Url = new UriBuilder( scheme: "https", - host: "citestcycle-intake." + CIVisibility.Settings.Site, - port: 443, - pathValue: "api/v2/citestcycle").Uri; + host: CIVisibility.Settings.Site, + portNumber: 443) + .Uri; } } diff --git a/tracer/src/Datadog.Trace/Ci/CIVisibility.cs b/tracer/src/Datadog.Trace/Ci/CIVisibility.cs index cf756f68f..78fd94cb1 100644 --- a/tracer/src/Datadog.Trace/Ci/CIVisibility.cs +++ b/tracer/src/Datadog.Trace/Ci/CIVisibility.cs @@ -13,7 +13,6 @@ using Datadog.Trace.Configuration; using Datadog.Trace.Logging; using Datadog.Trace.Pdb; -using Datadog.Trace.Util; namespace Datadog.Trace.Ci { @@ -21,10 +20,9 @@ internal class CIVisibility { private static readonly CIVisibilitySettings _settings = CIVisibilitySettings.FromDefaultSources(); private static int _firstInitialization = 1; - private static Lazy _enabledLazy = new Lazy(() => InternalEnabled(), true); internal static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(typeof(CIVisibility)); - public static bool Enabled => _enabledLazy.Value; + public static bool Enabled => false; public static bool IsRunning => Interlocked.CompareExchange(ref _firstInitialization, 0, 0) == 0; @@ -156,60 +154,5 @@ private static async Task ShutdownAsync() await InternalFlushAsync().ConfigureAwait(false); MethodSymbolResolver.Instance.Clear(); } - - private static bool InternalEnabled() - { - var processName = ProcessHelpers.GetCurrentProcessName() ?? string.Empty; - - // By configuration - if (_settings.Enabled) - { - // When is enabled by configuration we only enable it to the testhost child process if the process name is dotnet. - if (processName.Equals("dotnet", StringComparison.OrdinalIgnoreCase) && Environment.CommandLine.IndexOf("testhost.dll", StringComparison.OrdinalIgnoreCase) == -1) - { - Log.Information("CI Visibility disabled because the process name is 'dotnet' but the commandline doesn't contain 'testhost.dll': {cmdline}", Environment.CommandLine); - return false; - } - - Log.Information("CI Visibility Enabled by Configuration"); - return true; - } - - // Try to autodetect based in the domain name. - var domainName = AppDomain.CurrentDomain.FriendlyName ?? string.Empty; - if (domainName.StartsWith("testhost", StringComparison.Ordinal) || - domainName.StartsWith("vstest", StringComparison.Ordinal) || - domainName.StartsWith("xunit", StringComparison.Ordinal) || - domainName.StartsWith("nunit", StringComparison.Ordinal) || - domainName.StartsWith("MSBuild", StringComparison.Ordinal)) - { - Log.Information("CI Visibility Enabled by Domain name whitelist"); - PropagateCiVisibilityEnvironmentVariable(); - return true; - } - - // Try to autodetect based in the process name. - if (processName.StartsWith("testhost.", StringComparison.Ordinal)) - { - Log.Information("CI Visibility Enabled by Process name whitelist"); - PropagateCiVisibilityEnvironmentVariable(); - return true; - } - - return false; - - static void PropagateCiVisibilityEnvironmentVariable() - { - try - { - // Set the configuration key to propagate the configuration to child processes. - Environment.SetEnvironmentVariable(ConfigurationKeys.CIVisibility.Enabled, "1", EnvironmentVariableTarget.Process); - } - catch - { - // . - } - } - } } } diff --git a/tracer/src/Datadog.Trace/Ci/Configuration/CIVisibilitySettings.cs b/tracer/src/Datadog.Trace/Ci/Configuration/CIVisibilitySettings.cs index db7fd10a4..8280ab4d0 100644 --- a/tracer/src/Datadog.Trace/Ci/Configuration/CIVisibilitySettings.cs +++ b/tracer/src/Datadog.Trace/Ci/Configuration/CIVisibilitySettings.cs @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // +// Modified by Splunk Inc. + using System; using Datadog.Trace.Configuration; @@ -12,32 +14,24 @@ internal class CIVisibilitySettings { public CIVisibilitySettings(IConfigurationSource source) { - Enabled = source?.GetBool(ConfigurationKeys.CIVisibility.Enabled) ?? false; - Agentless = source?.GetBool(ConfigurationKeys.CIVisibility.AgentlessEnabled) ?? false; - Logs = source?.GetBool(ConfigurationKeys.CIVisibility.Logs) ?? false; - ApiKey = source?.GetString(ConfigurationKeys.ApiKey); - Site = source?.GetString(ConfigurationKeys.Site) ?? "datadoghq.com"; - AgentlessUrl = source?.GetString(ConfigurationKeys.CIVisibility.AgentlessUrl); + Enabled = false; + Agentless = false; + Logs = false; + ApiKey = string.Empty; + Site = "localhost"; + AgentlessUrl = string.Empty; // By default intake payloads has a 5MB limit MaximumAgentlessPayloadSize = 5 * 1024 * 1024; - ProxyHttps = source?.GetString(ConfigurationKeys.Proxy.ProxyHttps); - var proxyNoProxy = source?.GetString(ConfigurationKeys.Proxy.ProxyNoProxy) ?? string.Empty; - ProxyNoProxy = proxyNoProxy.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + ProxyHttps = string.Empty; + ProxyNoProxy = Array.Empty(); TracerSettings = new TracerSettings(source); - if (Logs) - { - // Enable the direct log submission - TracerSettings.LogSubmissionSettings.DirectLogSubmissionEnabledIntegrations.Add("XUnit"); - TracerSettings.LogSubmissionSettings.DirectLogSubmissionBatchPeriod = TimeSpan.FromSeconds(1); - } - // Code coverage - CodeCoverageEnabled = source?.GetBool(ConfigurationKeys.CIVisibility.CodeCoverage) ?? false; - CodeCoverageSnkFilePath = source?.GetString(ConfigurationKeys.CIVisibility.CodeCoverageSnkFile); + CodeCoverageEnabled = false; + CodeCoverageSnkFilePath = string.Empty; } /// diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/DirectSubmissionLogger.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/DirectSubmissionLogger.cs deleted file mode 100644 index 517f9ecc5..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/DirectSubmissionLogger.cs +++ /dev/null @@ -1,105 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.Formatting; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission -{ - /// - /// An implementation of ILogger for use with direct log submission - /// - internal class DirectSubmissionLogger - { - private readonly string _name; - private readonly IExternalScopeProvider? _scopeProvider; - private readonly IDatadogSink _sink; - private readonly LogFormatter? _logFormatter; - private readonly int _minimumLogLevel; - - internal DirectSubmissionLogger( - string name, - IExternalScopeProvider? scopeProvider, - IDatadogSink sink, - LogFormatter? logFormatter, - DirectSubmissionLogLevel minimumLogLevel) - { - _name = name; - _scopeProvider = scopeProvider; - _sink = sink; - _logFormatter = logFormatter; - _minimumLogLevel = (int)minimumLogLevel; - } - - /// - /// Writes a log entry. - /// - /// Entry will be written on this level. - /// Id of the event. - /// The entry to be written. Can be also an object. - /// The exception related to this entry. - /// Function to create a message of the and . - /// The type of the object to be written. - [DuckReverseMethod(ParameterTypeNames = new[] { "Microsoft.Extensions.Logging.LogLevel", "Microsoft.Extensions.Logging.EventId", "TState", "System.Exception", "Func`3" })] - public void Log(int logLevel, object eventId, TState state, Exception exception, Func formatter) - { - if (!IsEnabled(logLevel)) - { - return; - } - - // We render the event to a string immediately as we need to capture the properties - // This is more expensive from a CPU perspective, but saves having to persist the - // properties to a dictionary and rendering later - - var logEntry = new LogEntry( - DateTime.UtcNow, - logLevel, - _name, - eventId.GetHashCode(), - state, - exception, - formatter, - _scopeProvider); - var logFormatter = _logFormatter ?? TracerManager.Instance.DirectLogSubmission.Formatter; - var serializedLog = LoggerLogFormatter.FormatLogEvent(logFormatter, logEntry); - - var log = new LoggerDatadogLogEvent(serializedLog); - - _sink.EnqueueLog(log); - } - - /// - /// Checks if the given is enabled. - /// - /// Level to be checked. - /// true if enabled. - [DuckReverseMethod(ParameterTypeNames = new[] { "Microsoft.Extensions.Logging.LogLevel, Microsoft.Extensions.Logging.Abstractions" })] - public bool IsEnabled(int logLevel) => logLevel >= _minimumLogLevel; - - /// - /// Begins a logical operation scope. - /// - /// The identifier for the scope. - /// The type of the state to begin scope for. - /// An that ends the logical operation scope on dispose. - [DuckReverseMethod(ParameterTypeNames = new[] { "TState" })] - public IDisposable BeginScope(TState state) => _scopeProvider?.Push(state) ?? NullDisposable.Instance; - - private class NullDisposable : IDisposable - { - public static readonly NullDisposable Instance = new(); - - public void Dispose() - { - } - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/DirectSubmissionLoggerProvider.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/DirectSubmissionLoggerProvider.cs deleted file mode 100644 index 99f33129f..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/DirectSubmissionLoggerProvider.cs +++ /dev/null @@ -1,78 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System; -using System.Collections.Concurrent; -using System.ComponentModel; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission -{ - /// - /// Duck type for ILoggerProvider - /// - internal class DirectSubmissionLoggerProvider - { - private readonly Func _createLoggerFunc; - private readonly ConcurrentDictionary _loggers = new(); - private readonly IDatadogSink _sink; - private readonly LogFormatter? _formatter; - private readonly DirectSubmissionLogLevel _minimumLogLevel; - private IExternalScopeProvider? _scopeProvider; - - internal DirectSubmissionLoggerProvider(IDatadogSink sink, DirectSubmissionLogLevel minimumLogLevel) - : this(sink, formatter: null, minimumLogLevel) - { - } - - // used for testing - internal DirectSubmissionLoggerProvider( - IDatadogSink sink, - LogFormatter? formatter, - DirectSubmissionLogLevel minimumLogLevel) - { - _sink = sink; - _formatter = formatter; - _minimumLogLevel = minimumLogLevel; - _createLoggerFunc = CreateLoggerImplementation; - } - - /// - /// Creates a new instance. - /// - /// The category name for messages produced by the logger. - /// The instance of that was created. - [DuckReverseMethod] - public DirectSubmissionLogger CreateLogger(string categoryName) - { - return _loggers.GetOrAdd(categoryName, _createLoggerFunc); - } - - private DirectSubmissionLogger CreateLoggerImplementation(string name) - { - return new DirectSubmissionLogger(name, _scopeProvider, _sink, _formatter, _minimumLogLevel); - } - - /// - [DuckReverseMethod] - public void Dispose() - { - } - - /// - /// Method for ISupportExternalScope - /// - /// The provider of scope data - [DuckReverseMethod(ParameterTypeNames = new[] { "Microsoft.Extensions.Logging.IExternalScopeProvider, Microsoft.Extensions.Logging.Abstractions" })] - public void SetScopeProvider(IExternalScopeProvider scopeProvider) - { - _scopeProvider = scopeProvider; - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/Formatting/LogEntry.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/Formatting/LogEntry.cs deleted file mode 100644 index d83232799..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/Formatting/LogEntry.cs +++ /dev/null @@ -1,49 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.Formatting -{ - internal readonly struct LogEntry - { - public LogEntry( - DateTime timestamp, - int logLevel, - string category, - int eventId, - TState state, - Exception? exception, - Func formatter, - IExternalScopeProvider? scopeProvider) - { - Timestamp = timestamp; - LogLevel = logLevel; - Category = category; - EventId = eventId; - State = state; - Exception = exception; - Formatter = formatter; - ScopeProvider = scopeProvider; - } - - public DateTime Timestamp { get; } - - public int LogLevel { get; } - - public string Category { get; } - - public int EventId { get; } - - public TState State { get; } - - public Exception? Exception { get; } - - public Func Formatter { get; } - - public IExternalScopeProvider? ScopeProvider { get; } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/Formatting/LoggerLogFormatter.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/Formatting/LoggerLogFormatter.cs deleted file mode 100644 index 568ac3765..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/Formatting/LoggerLogFormatter.cs +++ /dev/null @@ -1,175 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System.Collections.Generic; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Util; -using Datadog.Trace.Vendors.Newtonsoft.Json; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.Formatting -{ - internal class LoggerLogFormatter - { - private const string MessageTemplateKey = "{OriginalFormat}"; - - public static string? FormatLogEvent(LogFormatter logFormatter, in LogEntry logEntry) - { - var message = logEntry.Formatter(logEntry.State, logEntry.Exception); - if (logEntry.Exception == null && message == null) - { - // No message! weird... - return null; - } - - var sb = StringBuilderCache.Acquire(StringBuilderCache.MaxBuilderSize); - - logFormatter.FormatLog( - sb, - logEntry, - logEntry.Timestamp, - message, - logEntry.EventId == 0 ? null : logEntry.EventId, - GetLogLevelString(logEntry.LogLevel), - logEntry.Exception, - (JsonTextWriter w, in LogEntry e) => RenderProperties(w, e)); - - return StringBuilderCache.GetStringAndRelease(sb); - } - - private static LogPropertyRenderingDetails RenderProperties(JsonTextWriter writer, in LogEntry logEntry) - { - var haveSource = false; - var haveService = false; - var haveHost = false; - var haveTags = false; - var haveVersion = false; - var haveEnv = false; - string? messageTemplate = null; - - if (logEntry.State is { } state) - { - if (state is IEnumerable> stateProperties) - { - foreach (var item in stateProperties) - { - // we don't need to write the message template - // (but should we) ? - var key = item.Key; - if (key != MessageTemplateKey) - { - haveSource |= LogFormatter.IsSourceProperty(key); - haveService |= LogFormatter.IsServiceProperty(key); - haveHost |= LogFormatter.IsHostProperty(key); - haveTags |= LogFormatter.IsTagsProperty(key); - haveEnv |= LogFormatter.IsEnvProperty(key); - haveVersion |= LogFormatter.IsVersionProperty(key); - - LogFormatter.WritePropertyName(writer, key); - LogFormatter.WriteValue(writer, item.Value); - } - else if (item.Value is string stringValue) - { - messageTemplate = stringValue; - } - } - } - else - { - writer.WritePropertyName("@s", escape: false); - LogFormatter.WriteValue(writer, state); - } - } - - if (logEntry.ScopeProvider is { } scopeProvider) - { - var writerWrapper = new WriterWrapper(writer); - scopeProvider.ForEachScope( - (scope, wrapper) => - { - // Add dictionary scopes to a properties object - // Theoretically we _should_ handle "duplicate" values, where the property has been added as state, - // And then we try and add it again, but the backend seems to handle this ok - if (scope is IEnumerable> scopeItems) - { - foreach (var item in scopeItems) - { - var key = item.Key; - haveSource |= LogFormatter.IsSourceProperty(key); - haveService |= LogFormatter.IsServiceProperty(key); - haveHost |= LogFormatter.IsHostProperty(key); - haveTags |= LogFormatter.IsTagsProperty(key); - haveEnv |= LogFormatter.IsEnvProperty(key); - haveVersion |= LogFormatter.IsVersionProperty(key); - - LogFormatter.WritePropertyName(writer, key); - LogFormatter.WriteValue(wrapper.Writer, item.Value); - } - } - else - { - wrapper.Values.Add(scope); // add to list for inclusion in scope array - } - }, - writerWrapper); - - if (writerWrapper.HasValues && writerWrapper.Values.Count > 0) - { - writer.WritePropertyName("Scopes", escape: false); - writer.WriteStartArray(); - - var values = writerWrapper.Values; - for (var i = 0; i < values.Count; i++) - { - LogFormatter.WriteValue(writer, values[i]); - } - - writer.WriteEndArray(); - } - } - - return new LogPropertyRenderingDetails( - hasRenderedSource: haveSource, - hasRenderedService: haveService, - hasRenderedHost: haveHost, - hasRenderedTags: haveTags, - hasRenderedEnv: haveEnv, - hasRenderedVersion: haveVersion, - messageTemplate: messageTemplate); - } - - private static string GetLogLevelString(int logLevel) => - logLevel switch - { - 0 => DirectSubmissionLogLevelExtensions.Verbose, // Trace - 1 => DirectSubmissionLogLevelExtensions.Debug, - 2 => DirectSubmissionLogLevelExtensions.Information, - 3 => DirectSubmissionLogLevelExtensions.Warning, - 4 => DirectSubmissionLogLevelExtensions.Error, - 5 => DirectSubmissionLogLevelExtensions.Fatal, // Critical - _ => DirectSubmissionLogLevelExtensions.Unknown, - }; - - private class WriterWrapper - { - private List? _values; - - public WriterWrapper(JsonWriter writer) - { - Writer = writer; - } - - public JsonWriter Writer { get; } - - public List Values - { - get => _values ??= new List(); - } - - public bool HasValues => _values is not null; - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/IExternalScopeProvider.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/IExternalScopeProvider.cs deleted file mode 100644 index 62bd121c7..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/IExternalScopeProvider.cs +++ /dev/null @@ -1,32 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.ComponentModel; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission -{ - /// - /// A duck type for Microsoft.Extensions.Logging.IExternalScopeProvider - /// - internal interface IExternalScopeProvider - { - /// - /// Adds scope object to the list - /// - /// The scope object - /// The IDisposable token that removes scope on dispose - IDisposable Push(object state); - - /// - /// Executes callback for each currently active scope objects in order of creation. All callbacks are guaranteed to be called inline from this method. - /// Note that original is Action<object, TState> callback - /// - /// The callback to be executed for every scope object - /// The state object to be passed into the callback. - /// The type of state to accept - void ForEachScope(Action callback, TState state); - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/ILoggerFactory.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/ILoggerFactory.cs deleted file mode 100644 index bdf21277f..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/ILoggerFactory.cs +++ /dev/null @@ -1,24 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.ComponentModel; -using System.Reflection; -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission -{ - /// - /// Duck type for ILogLevel - /// - internal interface ILoggerFactory : IDuckType - { - /// - /// Used to add the ILoggerProvider - /// - /// The ILoggerProvider to add - [Duck] - public void AddProvider(object provider); - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/LoggerDatadogLogEvent.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/LoggerDatadogLogEvent.cs deleted file mode 100644 index e0a63baaf..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/LoggerDatadogLogEvent.cs +++ /dev/null @@ -1,27 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System.Text; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission -{ - internal class LoggerDatadogLogEvent : DatadogLogEvent - { - private readonly string? _serializedEvent; - - public LoggerDatadogLogEvent(string? serializedEvent) - { - _serializedEvent = serializedEvent; - } - - public override void Format(StringBuilder sb, LogFormatter formatter) - { - sb.Append(_serializedEvent); - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/LoggerFactoryConstructorIntegration.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/LoggerFactoryConstructorIntegration.cs deleted file mode 100644 index e5e1cd4a3..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/LoggerFactoryConstructorIntegration.cs +++ /dev/null @@ -1,73 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System; -using System.ComponentModel; -using Datadog.Trace.ClrProfiler.CallTarget; -using Datadog.Trace.Configuration; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission -{ - /// - /// LoggerFactory() calltarget instrumentation for direct log submission - /// - [InstrumentMethod( - AssemblyName = "Microsoft.Extensions.Logging", - TypeName = "Microsoft.Extensions.Logging.LoggerFactory", - MethodName = ".ctor", - ReturnTypeName = ClrNames.Void, - ParameterTypeNames = new[] { "System.Collections.Generic.IEnumerable`1[Microsoft.Extensions.Logging.ILoggerProvider]", "Microsoft.Extensions.Options.IOptionsMonitor`1[Microsoft.Extensions.Logging.LoggerFilterOptions]" }, - MinimumVersion = "2.0.0", - MaximumVersion = "3.*.*", - IntegrationName = LoggerIntegrationCommon.IntegrationName)] - [InstrumentMethod( - AssemblyName = "Microsoft.Extensions.Logging", - TypeName = "Microsoft.Extensions.Logging.LoggerFactory", - MethodName = ".ctor", - ReturnTypeName = ClrNames.Void, - ParameterTypeNames = new[] { "System.Collections.Generic.IEnumerable`1[Microsoft.Extensions.Logging.ILoggerProvider]", "Microsoft.Extensions.Options.IOptionsMonitor`1[Microsoft.Extensions.Logging.LoggerFilterOptions]", "Microsoft.Extensions.Options.IOptions`1[Microsoft.Extensions.Logging.LoggerFactoryOptions]" }, - MinimumVersion = "5.0.0", - MaximumVersion = "6.*.*", - IntegrationName = LoggerIntegrationCommon.IntegrationName)] - [InstrumentMethod( - AssemblyName = "Microsoft.Extensions.Logging", - TypeName = "Microsoft.Extensions.Logging.LoggerFactory", - MethodName = ".ctor", - ReturnTypeName = ClrNames.Void, - ParameterTypeNames = new[] { "System.Collections.Generic.IEnumerable`1[Microsoft.Extensions.Logging.ILoggerProvider]", "Microsoft.Extensions.Options.IOptionsMonitor`1[Microsoft.Extensions.Logging.LoggerFilterOptions]", "Microsoft.Extensions.Options.IOptions`1[Microsoft.Extensions.Logging.LoggerFactoryOptions]", "Microsoft.Extensions.Logging.IExternalScopeProvider" }, - MinimumVersion = "7.0.0", - MaximumVersion = "7.*.*", - IntegrationName = LoggerIntegrationCommon.IntegrationName)] - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public class LoggerFactoryConstructorIntegration - { - /// - /// OnMethodEnd callback - /// - /// Type of the target - /// Instance value, aka `this` of the instrumented method. - /// Exception instance in case the original code threw an exception. - /// Calltarget state value - /// A default CallTargetReturn to satisfy the CallTarget contract - public static CallTargetReturn OnMethodEnd(TTarget instance, Exception? exception, CallTargetState state) - { - if (!TracerManager.Instance.DirectLogSubmission.Settings.IsIntegrationEnabled(IntegrationId.ILogger)) - { - return CallTargetReturn.GetDefault(); - } - - if (exception is not null) - { - // If there's an exception during the constructor, things aren't going to work anyway - return CallTargetReturn.GetDefault(); - } - - LoggerFactoryIntegrationCommon.AddDirectSubmissionLoggerProvider(instance); - return CallTargetReturn.GetDefault(); - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/LoggerFactoryIntegrationCommon.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/LoggerFactoryIntegrationCommon.cs deleted file mode 100644 index 47a93ec48..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/ILogger/DirectSubmission/LoggerFactoryIntegrationCommon.cs +++ /dev/null @@ -1,103 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System; -using System.Reflection; -using System.Reflection.Emit; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission -{ - internal static class LoggerFactoryIntegrationCommon - { - private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(typeof(LoggerFactoryIntegrationCommon)); - - // ReSharper disable once StaticMemberInGenericType - // Internal for testing - internal static readonly Type? ProviderInterfaces; - - static LoggerFactoryIntegrationCommon() - { - try - { - // The ILoggerProvider type is in a different assembly to the LoggerFactory, so go via the ILogger type - // returned by CreateLogger - var loggerFactoryType = typeof(TLoggerFactory); - var abstractionsAssembly = loggerFactoryType.GetMethod("CreateLogger")!.ReturnType.Assembly; - var iLoggerProviderType = abstractionsAssembly.GetType("Microsoft.Extensions.Logging.ILoggerProvider"); - var iSupportExternalScopeType = abstractionsAssembly.GetType("Microsoft.Extensions.Logging.ISupportExternalScope"); - - if (iSupportExternalScopeType is null) - { - // ISupportExternalScope is only available in v2.1+ - // We can just duck type ILoggerProvider directly - ProviderInterfaces = iLoggerProviderType; - return; - } - - // We need to implement both ILoggerProvider and ISupportExternalScope - // because LoggerFactory uses pattern matching to check if we implement the latter - // Duck Typing can currently only implement a single interface, so emit - // a new interface that implements both ILoggerProvider and ISupportExternalScope - // and duck cast to that - var thisAssembly = typeof(DirectSubmissionLoggerProvider).Assembly; - var assemblyName = new AssemblyName("DirectLogSubmissionILoggerFactoryAssembly") { Version = thisAssembly.GetName().Version }; - - var assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); - var moduleBuilder = (ModuleBuilder)assemblyBuilder.DefineDynamicModule("MainModule"); - - var typeBuilder = moduleBuilder.DefineType( - "DirectSubmissionLoggerProviderProxy", - TypeAttributes.Interface | TypeAttributes.Public | TypeAttributes.Abstract, - parent: null, - interfaces: new[] { iLoggerProviderType!, iSupportExternalScopeType }); - - ProviderInterfaces = typeBuilder.CreateTypeInfo()!.AsType(); - } - catch (Exception ex) - { - Log.Warning(ex, "Error loading logger factory types for " + typeof(TLoggerFactory)); - ProviderInterfaces = null; - } - } - - internal static void AddDirectSubmissionLoggerProvider(TLoggerFactory loggerFactory) - { - if (ProviderInterfaces is null) - { - // there was a problem loading the assembly for some reason - return; - } - - var provider = new DirectSubmissionLoggerProvider( - TracerManager.Instance.DirectLogSubmission.Sink, - TracerManager.Instance.DirectLogSubmission.Settings.MinimumLevel); - - AddDirectSubmissionLoggerProvider(loggerFactory, provider); - } - - // Internal for testing - internal static object? AddDirectSubmissionLoggerProvider(TLoggerFactory loggerFactory, DirectSubmissionLoggerProvider provider) - { - if (ProviderInterfaces is null) - { - // there was a problem loading the assembly for some reason - return null; - } - - var proxy = provider.DuckImplement(ProviderInterfaces); - if (loggerFactory is not null) - { - var loggerFactoryProxy = loggerFactory.DuckCast(); - loggerFactoryProxy.AddProvider(proxy); - Log.Information("Direct log submission via ILogger enabled"); - } - - return proxy; - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/AppenderCollectionIntegration.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/AppenderCollectionIntegration.cs deleted file mode 100644 index c6640d828..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/AppenderCollectionIntegration.cs +++ /dev/null @@ -1,61 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System; -using System.ComponentModel; -using Datadog.Trace.ClrProfiler.CallTarget; -using Datadog.Trace.Configuration; -using Datadog.Trace.Logging; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission -{ - /// - /// AppenderCollection.ToArray() calltarget instrumentation - /// - [InstrumentMethod( - AssemblyName = "log4net", - TypeName = "log4net.Appender.AppenderCollection", - MethodName = "ToArray", - ReturnTypeName = "log4net.Appender.IAppender[]", - ParameterTypeNames = new string[0], - MinimumVersion = "2.0.0", - MaximumVersion = "2.*.*", - IntegrationName = nameof(IntegrationId.Log4Net))] - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public class AppenderCollectionIntegration - { - private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(); - private static bool _logWritten = false; - - /// - /// OnMethodEnd callback - /// - /// Type of the target - /// The type of the response - /// Instance value, aka `this` of the instrumented method. - /// The returned ILoggerWrapper - /// Exception instance in case the original code threw an exception. - /// Calltarget state value - /// A default CallTargetReturn to satisfy the CallTarget contract - public static CallTargetReturn OnMethodEnd(TTarget instance, TResponse response, Exception exception, CallTargetState state) - { - if (!TracerManager.Instance.DirectLogSubmission.Settings.IsIntegrationEnabled(IntegrationId.Log4Net)) - { - return new CallTargetReturn(response); - } - - var updatedResponse = Log4NetCommon.AddAppenderToResponse(response, DirectSubmissionLog4NetAppender.Instance); - if (!_logWritten) - { - _logWritten = true; - Log.Information("Direct log submission via Log4Net enabled"); - } - - return new CallTargetReturn(updatedResponse); - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/AppenderCollectionLegacyIntegration.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/AppenderCollectionLegacyIntegration.cs deleted file mode 100644 index 1bb498d40..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/AppenderCollectionLegacyIntegration.cs +++ /dev/null @@ -1,62 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System; -using System.ComponentModel; -using Datadog.Trace.ClrProfiler.CallTarget; -using Datadog.Trace.Configuration; -using Datadog.Trace.Logging; -using Datadog.Trace.Logging.DirectSubmission; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission -{ - /// - /// AppenderCollection.ToArray() calltarget instrumentation - /// - [InstrumentMethod( - AssemblyName = "log4net", - TypeName = "log4net.Appender.AppenderCollection", - MethodName = "ToArray", - ReturnTypeName = "log4net.Appender.IAppender[]", - ParameterTypeNames = new string[0], - MinimumVersion = "1.0.0", - MaximumVersion = "1.*.*", - IntegrationName = nameof(IntegrationId.Log4Net))] - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public class AppenderCollectionLegacyIntegration - { - private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(); - private static bool _logWritten = false; - - /// - /// OnMethodEnd callback - /// - /// Type of the target - /// The type of the response - /// Instance value, aka `this` of the instrumented method. - /// The returned ILoggerWrapper - /// Exception instance in case the original code threw an exception. - /// Calltarget state value - /// A default CallTargetReturn to satisfy the CallTarget contract - public static CallTargetReturn OnMethodEnd(TTarget instance, TResponse response, Exception exception, CallTargetState state) - { - if (!TracerManager.Instance.DirectLogSubmission.Settings.IsIntegrationEnabled(IntegrationId.Log4Net)) - { - return new CallTargetReturn(response); - } - - var updatedResponse = Log4NetCommon.AddAppenderToResponse(response, DirectSubmissionLog4NetLegacyAppender.Instance); - if (!_logWritten) - { - _logWritten = true; - Log.Information("Direct log submission via Log4Net Legacy enabled"); - } - - return new CallTargetReturn(updatedResponse); - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/DirectSubmissionLog4NetAppender.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/DirectSubmissionLog4NetAppender.cs deleted file mode 100644 index fec075483..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/DirectSubmissionLog4NetAppender.cs +++ /dev/null @@ -1,78 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System.Threading; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Sink; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission -{ - /// - /// Duck type for IAppender - /// - internal class DirectSubmissionLog4NetAppender - { - private static DirectSubmissionLog4NetAppender _instance = null!; - - private readonly IDatadogSink _sink; - private readonly DirectSubmissionLogLevel _minimumLevel; - - // internal for testing - internal DirectSubmissionLog4NetAppender(IDatadogSink sink, DirectSubmissionLogLevel minimumLevel) - { - _sink = sink; - _minimumLevel = minimumLevel; - } - - internal static DirectSubmissionLog4NetAppender Instance - { - get { return LazyInitializer.EnsureInitialized(ref _instance, CreateStaticInstance); } - } - - /// - /// Gets or sets the name of this appender - /// - [DuckReverseMethod] - public string Name { get; set; } = "Datadog"; - - /// - /// Closes the appender and releases resources - /// - [DuckReverseMethod] - public void Close() - { - } - - /// - /// Log the logging event in Appender specific way. - /// - /// The logging event - [DuckReverseMethod(ParameterTypeNames = new[] { "log4net.Core.LoggingEvent, log4net " })] - public void DoAppend(ILoggingEventDuck? logEvent) - { - if (logEvent is null) - { - return; - } - - if (logEvent.Level.ToStandardLevel() < _minimumLevel) - { - return; - } - - var log = new Log4NetDatadogLogEvent(logEvent, logEvent.TimeStampUtc); - _sink.EnqueueLog(log); - } - - private static DirectSubmissionLog4NetAppender CreateStaticInstance() - { - return new DirectSubmissionLog4NetAppender( - TracerManager.Instance.DirectLogSubmission.Sink, - TracerManager.Instance.DirectLogSubmission.Settings.MinimumLevel); - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/DirectSubmissionLog4NetLegacyAppender.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/DirectSubmissionLog4NetLegacyAppender.cs deleted file mode 100644 index 7d3cc5726..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/DirectSubmissionLog4NetLegacyAppender.cs +++ /dev/null @@ -1,78 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System.Threading; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Sink; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission -{ - /// - /// Duck type for IAppender - /// - internal class DirectSubmissionLog4NetLegacyAppender - { - private static DirectSubmissionLog4NetLegacyAppender _instance = null!; - - private readonly IDatadogSink _sink; - private readonly DirectSubmissionLogLevel _minimumLevel; - - // internal for testing - internal DirectSubmissionLog4NetLegacyAppender(IDatadogSink sink, DirectSubmissionLogLevel minimumLevel) - { - _sink = sink; - _minimumLevel = minimumLevel; - } - - internal static DirectSubmissionLog4NetLegacyAppender Instance - { - get { return LazyInitializer.EnsureInitialized(ref _instance, CreateStaticInstance); } - } - - /// - /// Gets or sets the name of this appender - /// - [DuckReverseMethod] - public string Name { get; set; } = "Datadog"; - - /// - /// Closes the appender and releases resources - /// - [DuckReverseMethod] - public void Close() - { - } - - /// - /// Log the logging event in Appender specific way. - /// - /// The logging event - [DuckReverseMethod(ParameterTypeNames = new[] { "log4net.Core.LoggingEvent, log4net " })] - public void DoAppend(ILoggingEventLegacyDuck? logEvent) - { - if (logEvent is null) - { - return; - } - - if (logEvent.Level.ToStandardLevel() < _minimumLevel) - { - return; - } - - var log = new Log4NetDatadogLogEvent(logEvent, logEvent.TimeStamp.ToUniversalTime()); - _sink.EnqueueLog(log); - } - - private static DirectSubmissionLog4NetLegacyAppender CreateStaticInstance() - { - return new DirectSubmissionLog4NetLegacyAppender( - TracerManager.Instance.DirectLogSubmission.Sink, - TracerManager.Instance.DirectLogSubmission.Settings.MinimumLevel); - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/ILoggingEventDuck.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/ILoggingEventDuck.cs deleted file mode 100644 index 44826d527..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/ILoggingEventDuck.cs +++ /dev/null @@ -1,20 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission -{ - /// - /// Duck type for LoggingEvent - /// - internal interface ILoggingEventDuck : ILoggingEventDuckBase - { - /// - /// Gets the UTC time the event was logged - /// - public DateTime TimeStampUtc { get; } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/ILoggingEventDuckBase.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/ILoggingEventDuckBase.cs deleted file mode 100644 index 897e3cf8f..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/ILoggingEventDuckBase.cs +++ /dev/null @@ -1,47 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Collections; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission -{ - /// - /// Duck type for LoggingEvent - /// - internal interface ILoggingEventDuckBase - { - /// - /// Gets the name of the logger that logged the event. - /// - public string LoggerName { get; } - - /// - /// Gets the Level of the logging event - /// - public LevelDuck Level { get; } - - /// - /// Gets the application supplied message. - /// - public object MessageObject { get; } - - /// - /// Gets the message, rendered through the RendererMap". - /// - public string RenderedMessage { get; } - - /// - /// Gets the exception associated with the event - /// - public string GetExceptionString(); - - /// - /// Get all the composite properties in this event - /// - /// Dictionary containing all the properties - public IDictionary GetProperties(); - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/ILoggingEventLegacyDuck.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/ILoggingEventLegacyDuck.cs deleted file mode 100644 index 65d970809..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/ILoggingEventLegacyDuck.cs +++ /dev/null @@ -1,20 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission -{ - /// - /// Duck type for LoggingEvent - /// - internal interface ILoggingEventLegacyDuck : ILoggingEventDuckBase - { - /// - /// Gets the Local time the event was logged - /// - public DateTime TimeStamp { get; } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/LevelDuck.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/LevelDuck.cs deleted file mode 100644 index a5ab7fe12..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/LevelDuck.cs +++ /dev/null @@ -1,21 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission -{ - /// - /// Duck type for Level - /// - [DuckCopy] - internal struct LevelDuck - { - /// - /// Gets the level value - /// - public int Value; - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/LevelDuckExtensions.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/LevelDuckExtensions.cs deleted file mode 100644 index 6bf20fb66..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/LevelDuckExtensions.cs +++ /dev/null @@ -1,40 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using Datadog.Trace.Logging.DirectSubmission; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission -{ - internal static class LevelDuckExtensions - { - private const int DebugThreshold = 30000; - private const int InfoThreshold = 40000; - private const int WarningThreshold = 60000; - private const int ErrorThreshold = 70000; - private const int FatalThreshold = 80000; - - public static DirectSubmissionLogLevel ToStandardLevel(this LevelDuck level) - => level.Value switch - { - < DebugThreshold => DirectSubmissionLogLevel.Verbose, // ALL/Finest/Verbose/FINER/Trace/ - >= DebugThreshold and < InfoThreshold => DirectSubmissionLogLevel.Debug, - >= InfoThreshold and < WarningThreshold => DirectSubmissionLogLevel.Information, - >= WarningThreshold and < ErrorThreshold => DirectSubmissionLogLevel.Warning, - >= ErrorThreshold and < FatalThreshold => DirectSubmissionLogLevel.Error, - >= FatalThreshold => DirectSubmissionLogLevel.Fatal, // SEVERE, Critical, Alert, Fatal, Emergency - }; - - public static string ToStandardLevelString(this LevelDuck level) - => level.Value switch - { - < DebugThreshold => DirectSubmissionLogLevelExtensions.Verbose, // ALL/Finest/Verbose/FINER/Trace/ - >= DebugThreshold and < InfoThreshold => DirectSubmissionLogLevelExtensions.Debug, - >= InfoThreshold and < WarningThreshold => DirectSubmissionLogLevelExtensions.Information, - >= WarningThreshold and < ErrorThreshold => DirectSubmissionLogLevelExtensions.Warning, - >= ErrorThreshold and < FatalThreshold => DirectSubmissionLogLevelExtensions.Error, - >= FatalThreshold => DirectSubmissionLogLevelExtensions.Fatal, // SEVERE, Critical, Alert, Fatal, Emergency - }; - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/Log4NetCommon.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/Log4NetCommon.cs deleted file mode 100644 index 3ef44bdab..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/Log4NetCommon.cs +++ /dev/null @@ -1,65 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission -{ - internal class Log4NetCommon - { - private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(typeof(Log4NetCommon)); - - // ReSharper disable StaticMemberInGenericType - private static readonly Type AppenderElementType; - private static object? _appenderProxy; - - static Log4NetCommon() - { - AppenderElementType = typeof(TResponseArray).GetElementType()!; - } - - public static TResponseArray AddAppenderToResponse(TResponseArray originalResponseArray, TAppender appender) - { - try - { - if (originalResponseArray is null) - { - return originalResponseArray; - } - - var originalArray = (Array)(object)originalResponseArray; - var originalArrayLength = originalArray.Length; - - var finalArray = Array.CreateInstance(AppenderElementType, originalArrayLength + 1); - if (originalArrayLength > 0) - { - Array.Copy(originalArray, finalArray, originalArrayLength); - } - - if (_appenderProxy is null) - { - if (appender is null) - { - Log.Error("Error adding Log4Net appender to response: appender is null"); - return originalResponseArray; - } - - _appenderProxy = appender.DuckImplement(AppenderElementType); - } - - finalArray.SetValue(_appenderProxy, finalArray.Length - 1); - return (TResponseArray)(object)finalArray; - } - catch (Exception ex) - { - Log.Error(ex, "Error adding Log4Net appender to response"); - return originalResponseArray; - } - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/Log4NetDatadogLogEvent.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/Log4NetDatadogLogEvent.cs deleted file mode 100644 index 751a9c8d6..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/Log4NetDatadogLogEvent.cs +++ /dev/null @@ -1,30 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System; -using System.Text; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission -{ - internal class Log4NetDatadogLogEvent : DatadogLogEvent - { - private readonly ILoggingEventDuckBase _logEvent; - private readonly DateTime _timestamp; - - public Log4NetDatadogLogEvent(ILoggingEventDuckBase logEvent, DateTime timestamp) - { - _logEvent = logEvent; - _timestamp = timestamp; - } - - public override void Format(StringBuilder sb, LogFormatter formatter) - { - Log4NetLogFormatter.FormatLogEvent(formatter, sb, _logEvent, _timestamp); - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/Log4NetLogFormatter.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/Log4NetLogFormatter.cs deleted file mode 100644 index ddbb3fcb0..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/Log4NetLogFormatter.cs +++ /dev/null @@ -1,92 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System; -using System.Collections; -using System.Reflection; -using System.Text; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Vendors.Newtonsoft.Json; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission -{ - internal class Log4NetLogFormatter - { - public static void FormatLogEvent(LogFormatter logFormatter, StringBuilder sb, ILoggingEventDuckBase logEntry, DateTime timestamp) - { - logFormatter.FormatLog( - sb, - logEntry, - timestamp, - logEntry.RenderedMessage, - eventId: null, - logEntry.Level.ToStandardLevelString(), - exception: null, // We can't pass the exception here, as it might be null if the event has been serialized - (JsonTextWriter w, in ILoggingEventDuckBase e) => RenderProperties(w, in e)); - } - - private static LogPropertyRenderingDetails RenderProperties(JsonTextWriter writer, in ILoggingEventDuckBase logEntry) - { - var haveSource = false; - var haveService = false; - var haveHost = false; - var haveTags = false; - var haveEnv = false; - var haveVersion = false; - - var exception = logEntry.GetExceptionString(); - if (!string.IsNullOrEmpty(exception)) - { - writer.WritePropertyName("@x", escape: false); - writer.WriteValue(exception); - } - - var properties = logEntry.GetProperties(); - foreach (var keyObj in properties.Keys) - { - var name = keyObj as string; - if (name is null || name.StartsWith("log4net:")) - { - continue; - } - - var value = properties[name]; - - switch (value) - { - case MethodInfo _: - case Assembly _: - case Module _: - continue; - default: - haveSource |= LogFormatter.IsSourceProperty(name); - haveService |= LogFormatter.IsServiceProperty(name); - haveHost |= LogFormatter.IsHostProperty(name); - haveTags |= LogFormatter.IsTagsProperty(name); - haveEnv |= LogFormatter.IsEnvProperty(name); - haveVersion |= LogFormatter.IsVersionProperty(name); - - LogFormatter.WritePropertyName(writer, name); - LogFormatter.WriteValue(writer, value); - break; - } - } - - // The message object could be anything, so only generate an eventID if we have a string message - var messageTemplate = logEntry.MessageObject as string; - - return new LogPropertyRenderingDetails( - hasRenderedSource: haveSource, - hasRenderedService: haveService, - hasRenderedHost: haveHost, - hasRenderedTags: haveTags, - hasRenderedEnv: haveEnv, - hasRenderedVersion: haveVersion, - messageTemplate: messageTemplate); - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/DirectSubmissionNLogLegacyTarget.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/DirectSubmissionNLogLegacyTarget.cs deleted file mode 100644 index 2a7843788..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/DirectSubmissionNLogLegacyTarget.cs +++ /dev/null @@ -1,80 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System; -using System.Collections.Generic; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Formatting; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission -{ - /// - /// NLog Target that sends logs directly to Datadog for NLog <4.5 - /// - internal class DirectSubmissionNLogLegacyTarget - { - private readonly IDatadogSink _sink; - private readonly int _minimumLevel; - private readonly LogFormatter? _formatter; - private Func?>? _getProperties = null; - - internal DirectSubmissionNLogLegacyTarget(IDatadogSink sink, DirectSubmissionLogLevel minimumLevel) - : this(sink, minimumLevel, formatter: null) - { - } - - // internal for testing - internal DirectSubmissionNLogLegacyTarget( - IDatadogSink sink, - DirectSubmissionLogLevel minimumLevel, - LogFormatter? formatter) - { - _sink = sink; - _formatter = formatter; - _minimumLevel = (int)minimumLevel; - } - - /// - /// Writes logging event to the log target - /// - /// Logging event to be written out - [DuckReverseMethod(ParameterTypeNames = new[] { "NLog.LogEventInfo, NLog" })] - public void Write(ILogEventInfoLegacyProxy? logEventInfo) - { - if (logEventInfo is null) - { - return; - } - - if (logEventInfo.Level.Ordinal < _minimumLevel) - { - return; - } - - var contextProperties = _getProperties?.Invoke(); - var eventProperties = logEventInfo.Properties is { Count: > 0 } props ? props : null; - - // We render the event to a string immediately as we need to capture the properties - // This is more expensive from a CPU perspective, but is necessary as the properties - // won't necessarily be serialized correctly otherwise (e.g. dd_span_id/dd_trace_id) - - var logEvent = new LogEntry(logEventInfo, contextProperties, eventProperties); - var logFormatter = _formatter ?? TracerManager.Instance.DirectLogSubmission.Formatter; - var serializedLog = NLogLogFormatter.FormatLogEvent(logFormatter, logEvent); - - _sink.EnqueueLog(new NLogDatadogLogEvent(serializedLog)); - } - - internal void SetGetContextPropertiesFunc(Func?> func) - { - _getProperties = func; - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/DirectSubmissionNLogTarget.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/DirectSubmissionNLogTarget.cs deleted file mode 100644 index 7ed2faca7..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/DirectSubmissionNLogTarget.cs +++ /dev/null @@ -1,83 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Formatting; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission -{ - /// - /// NLog Target that sends logs directly to Datadog - /// - internal class DirectSubmissionNLogTarget - { - private readonly IDatadogSink _sink; - private readonly int _minimumLevel; - private readonly LogFormatter? _formatter; - private ITargetWithContextBaseProxy? _baseProxy; - - internal DirectSubmissionNLogTarget(IDatadogSink sink, DirectSubmissionLogLevel minimumLevel) - : this(sink, minimumLevel, formatter: null) - { - } - - // internal for testing - internal DirectSubmissionNLogTarget( - IDatadogSink sink, - DirectSubmissionLogLevel minimumLevel, - LogFormatter? formatter) - { - _sink = sink; - _formatter = formatter; - _minimumLevel = (int)minimumLevel; - } - - /// - /// Writes logging event to the log target - /// - /// Logging event to be written out - [DuckReverseMethod(ParameterTypeNames = new[] { "NLog.LogEventInfo, NLog" })] - public void Write(ILogEventInfoProxy? logEventInfo) - { - if (logEventInfo is null) - { - return; - } - - if (logEventInfo.Level.Ordinal < _minimumLevel) - { - return; - } - - // Nlog automatically includes all the properties from the event, so don't need fallback properties - var mappedProperties = _baseProxy?.GetAllProperties(logEventInfo); - - // We render the event to a string immediately as we need to capture the properties - // This is more expensive from a CPU perspective, but is necessary as the properties - // won't necessarily be serialized correctly otherwise (e.g. dd_span_id/dd_trace_id) - - var logEvent = new LogEntry(logEventInfo, mappedProperties, fallbackProperties: null); - var logFormatter = _formatter ?? TracerManager.Instance.DirectLogSubmission.Formatter; - var serializedLog = NLogLogFormatter.FormatLogEvent(logFormatter, logEvent); - - _sink.EnqueueLog(new NLogDatadogLogEvent(serializedLog)); - } - - internal void SetBaseProxy(ITargetWithContextBaseProxy baseProxy) - { - _baseProxy = baseProxy; - _baseProxy.IncludeEventProperties = true; - _baseProxy.IncludeMdc = true; - _baseProxy.IncludeMdlc = true; - _baseProxy.IncludeNdc = true; - _baseProxy.IncludeNdlc = true; - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Formatting/LogEntry.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Formatting/LogEntry.cs deleted file mode 100644 index 026065f45..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Formatting/LogEntry.cs +++ /dev/null @@ -1,30 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System.Collections.Generic; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Formatting -{ - internal readonly struct LogEntry - { - public LogEntry( - ILogEventInfoProxyBase logEventInfo, - IDictionary? properties, - IDictionary? fallbackProperties) - { - LogEventInfo = logEventInfo; - Properties = properties; - FallbackProperties = fallbackProperties; - } - - public ILogEventInfoProxyBase LogEventInfo { get; } - - public IDictionary? Properties { get; } - - public IDictionary? FallbackProperties { get; } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Formatting/NLogDatadogLogEvent.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Formatting/NLogDatadogLogEvent.cs deleted file mode 100644 index 124711d2a..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Formatting/NLogDatadogLogEvent.cs +++ /dev/null @@ -1,28 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Collections.Generic; -using System.Text; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Formatting -{ - internal class NLogDatadogLogEvent : DatadogLogEvent - { - private readonly string _serializedEvent; - - public NLogDatadogLogEvent(string serializedEvent) - { - _serializedEvent = serializedEvent; - } - - public override void Format(StringBuilder sb, LogFormatter formatter) - { - sb.Append(_serializedEvent); - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Formatting/NLogLogFormatter.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Formatting/NLogLogFormatter.cs deleted file mode 100644 index e58f0dd2d..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Formatting/NLogLogFormatter.cs +++ /dev/null @@ -1,104 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Text; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Util; -using Datadog.Trace.Vendors.Newtonsoft.Json; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Formatting -{ - internal class NLogLogFormatter - { - public static string FormatLogEvent(LogFormatter logFormatter, in LogEntry logEntryWrapper) - { - var sb = StringBuilderCache.Acquire(StringBuilderCache.MaxBuilderSize); - FormatLogEvent(logFormatter, sb, logEntryWrapper); - return StringBuilderCache.GetStringAndRelease(sb); - } - - public static void FormatLogEvent(LogFormatter logFormatter, StringBuilder sb, in LogEntry logEntryWrapper) - { - var logEntry = logEntryWrapper.LogEventInfo; - logFormatter.FormatLog( - sb, - logEntryWrapper, - logEntry.TimeStamp.ToUniversalTime(), - logEntry.FormattedMessage, - eventId: null, - GetLogLevelString(logEntry.Level), - logEntry.Exception, - (JsonTextWriter w, in LogEntry e) => RenderProperties(w, e)); - } - - private static LogPropertyRenderingDetails RenderProperties(JsonTextWriter writer, in LogEntry logEntryWrapper) - { - var haveSource = false; - var haveService = false; - var haveHost = false; - var haveTags = false; - var haveEnv = false; - var haveVersion = false; - - if (logEntryWrapper.Properties is not null) - { - foreach (var kvp in logEntryWrapper.Properties) - { - var name = kvp.Key; - haveSource |= LogFormatter.IsSourceProperty(name); - haveService |= LogFormatter.IsServiceProperty(name); - haveHost |= LogFormatter.IsHostProperty(name); - haveTags |= LogFormatter.IsTagsProperty(name); - haveEnv |= LogFormatter.IsEnvProperty(name); - haveVersion |= LogFormatter.IsVersionProperty(name); - - LogFormatter.WritePropertyName(writer, name); - LogFormatter.WriteValue(writer, kvp.Value); - } - } - else if (logEntryWrapper.FallbackProperties is not null) - { - foreach (var kvp in logEntryWrapper.FallbackProperties) - { - var name = kvp.Key.ToString(); - haveSource |= LogFormatter.IsSourceProperty(name); - haveService |= LogFormatter.IsServiceProperty(name); - haveHost |= LogFormatter.IsHostProperty(name); - haveTags |= LogFormatter.IsTagsProperty(name); - haveEnv |= LogFormatter.IsEnvProperty(name); - haveVersion |= LogFormatter.IsVersionProperty(name); - - LogFormatter.WritePropertyName(writer, name); - LogFormatter.WriteValue(writer, kvp.Value); - } - } - - return new LogPropertyRenderingDetails( - hasRenderedSource: haveSource, - hasRenderedService: haveService, - hasRenderedHost: haveHost, - hasRenderedTags: haveTags, - hasRenderedEnv: haveEnv, - hasRenderedVersion: haveVersion, - messageTemplate: logEntryWrapper.LogEventInfo.Message); - } - - private static string GetLogLevelString(LogLevelProxy logLevel) => - logLevel.Ordinal switch - { - 0 => DirectSubmissionLogLevelExtensions.Verbose, - 1 => DirectSubmissionLogLevelExtensions.Debug, - 2 => DirectSubmissionLogLevelExtensions.Information, - 3 => DirectSubmissionLogLevelExtensions.Warning, - 4 => DirectSubmissionLogLevelExtensions.Error, - 5 => DirectSubmissionLogLevelExtensions.Fatal, - // Technically there's a 6, off, but should never have this level in a log message - _ => DirectSubmissionLogLevelExtensions.Unknown, - }; - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/LogFactoryGetConfigurationForLoggerInstrumentation.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/LogFactoryGetConfigurationForLoggerInstrumentation.cs deleted file mode 100644 index 19a6254f0..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/LogFactoryGetConfigurationForLoggerInstrumentation.cs +++ /dev/null @@ -1,59 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System.ComponentModel; -using Datadog.Trace.ClrProfiler.CallTarget; -using Datadog.Trace.Configuration; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission -{ - /// - /// LogFactory.GetConfigurationForLogger calltarget instrumentation - /// - [InstrumentMethod( - AssemblyName = "NLog", - TypeName = "NLog.LogFactory", - MethodName = "GetConfigurationForLogger", - ReturnTypeName = ClrNames.Void, - ParameterTypeNames = new[] { ClrNames.String, "NLog.Config.LoggingConfiguration" }, - MinimumVersion = "2.1.0", - MaximumVersion = "4.*.*", - IntegrationName = NLogConstants.IntegrationName)] - [InstrumentMethod( - AssemblyName = "NLog", - TypeName = "NLog.LogFactory", - MethodName = "BuildLoggerConfiguration", - ReturnTypeName = ClrNames.Void, - ParameterTypeNames = new[] { ClrNames.String, "NLog.Config.LoggingConfiguration" }, - MinimumVersion = "5.0.0", - MaximumVersion = "5.*.*", - IntegrationName = NLogConstants.IntegrationName)] - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public class LogFactoryGetConfigurationForLoggerInstrumentation - { - /// - /// OnMethodBegin callback - /// - /// Type of the target - /// Type of the LoggingConfiguration object - /// Instance value, aka `this` of the instrumented method - /// The name of the logger - /// The logging configuration - /// Calltarget state value - public static CallTargetState OnMethodBegin(TTarget instance, string name, TLoggingConfiguration configuration) - { - if (TracerManager.Instance.DirectLogSubmission.Settings.IsIntegrationEnabled(IntegrationId.NLog) - && configuration is not null) - { - // if configuration is not-null, we've already checked that NLog is enabled - NLogCommon.AddDatadogTarget(configuration); - } - - return CallTargetState.GetDefault(); - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/NLogCommon.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/NLogCommon.cs deleted file mode 100644 index b98000c92..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/NLogCommon.cs +++ /dev/null @@ -1,404 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Reflection.Emit; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies.Pre43; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging; -using Datadog.Trace.Util; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission -{ - internal static class NLogCommon - { - private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(typeof(NLogCommon)); - - // ReSharper disable StaticMemberInGenericType - // ReSharper disable InconsistentNaming - private static readonly NLogVersion _nLogVersion; - private static readonly Type? _targetType; - - private static readonly bool _hasMappedDiagnosticsContext; - private static readonly bool _isModernMappedDiagnosticsContext; - private static readonly MappedDiagnosticsProxy? _mdc; - private static readonly MappedDiagnosticsContextLegacyProxy _mdcLegacy; - private static readonly bool _hasMappedDiagnosticsLogicalContext; - private static readonly bool _isModernMappedDiagnosticsLogicalContext; - private static readonly MappedDiagnosticsProxy? _mdlc; - private static readonly MappedDiagnosticsLogicalContextLegacyProxy _mdlcLegacy; - - private static readonly object? _targetProxy; - private static readonly Func? _createLoggingRuleFunc; - // ReSharper restore InconsistentNaming - - static NLogCommon() - { - try - { - var nlogAssembly = typeof(TTarget).Assembly; - _targetType = nlogAssembly.GetType("NLog.Targets.TargetWithContext"); - if (_targetType is not null) - { - _nLogVersion = NLogVersion.NLog45; - - _targetProxy = CreateNLogTargetProxy(new DirectSubmissionNLogTarget( - TracerManager.Instance.DirectLogSubmission.Sink, - TracerManager.Instance.DirectLogSubmission.Settings.MinimumLevel)); - return; - } - - _targetType = nlogAssembly.GetType("NLog.Targets.Target"); - - // Type was added in NLog 4.3, so we can use it to safely determine the version - var testType = nlogAssembly.GetType("NLog.Config.ExceptionRenderingFormat"); - _nLogVersion = testType is null ? NLogVersion.NLogPre43 : NLogVersion.NLog43To45; - - TryGetMdcProxy(nlogAssembly, out _hasMappedDiagnosticsContext, out _isModernMappedDiagnosticsContext, out _mdc, out _mdcLegacy); - TryGetMdlcProxy(nlogAssembly, out _hasMappedDiagnosticsLogicalContext, out _isModernMappedDiagnosticsLogicalContext, out _mdlc, out _mdlcLegacy); - - _targetProxy = CreateNLogTargetProxy(new DirectSubmissionNLogLegacyTarget( - TracerManager.Instance.DirectLogSubmission.Sink, - TracerManager.Instance.DirectLogSubmission.Settings.MinimumLevel)); - - if (_nLogVersion == NLogVersion.NLogPre43) - { - _createLoggingRuleFunc = CreateLoggingRuleActivator(nlogAssembly); - } - } - catch (Exception ex) - { - Log.Error(ex, "Error creating NLog target proxies for direct log shipping"); - _targetType = null; - _targetProxy = null; - } - } - - internal enum NLogVersion - { - NLog45 = 0, - NLog43To45 = 1, - NLogPre43 = 2, - } - - public static void AddDatadogTarget(object loggingConfiguration) - { - if (_targetProxy is null) - { - return; - } - - switch (_nLogVersion) - { - case NLogVersion.NLog45: - AddDatadogTargetNLog45(loggingConfiguration, _targetProxy); - break; - case NLogVersion.NLog43To45: - AddDatadogTargetNLog43To45(loggingConfiguration, _targetProxy); - break; - default: - AddDatadogTargetNLogPre43(loggingConfiguration, _targetProxy); - break; - } - } - - public static IDictionary? GetContextProperties() - { - IDictionary? properties = null; - if (_hasMappedDiagnosticsContext) - { - if (_isModernMappedDiagnosticsContext) - { - var names = _mdc!.GetNames(); // C# isn't clever enough to figure that this is never null here - properties = new Dictionary(names.Count); - foreach (var name in names) - { - if (!string.IsNullOrEmpty(name)) - { - // could be a or a , depending on NLog version - properties[name] = _mdc.GetObject(name); - } - } - } - else if (_mdcLegacy.ThreadDictionary is { } dict) - { - properties = new Dictionary(dict.Count); - foreach (string? name in dict.Keys) - { - if (!string.IsNullOrEmpty(name)) - { - // could be a or a , depending on NLog version - properties[name!] = dict[name]; - } - } - } - } - - if (_hasMappedDiagnosticsLogicalContext) - { - if (_isModernMappedDiagnosticsLogicalContext) - { - var names = _mdlc!.GetNames(); // C# isn't clever enough to figure that this is never null here - properties ??= new Dictionary(names.Count); - foreach (var name in names) - { - if (!string.IsNullOrEmpty(name)) - { - // could be a or a , depending on NLog version - properties[name] = _mdlc.GetObject(name); - } - } - } - else if (_mdlcLegacy.LogicalThreadDictionary is { } dict) - { - properties ??= new Dictionary(dict.Count); - foreach (string? name in dict.Keys) - { - if (!string.IsNullOrEmpty(name)) - { - // could be a or a , depending on NLog version - properties[name!] = dict[name]; - } - } - } - } - - return properties; - } - - // internal for testing - internal static void AddDatadogTargetNLog45(object loggingConfiguration, object targetProxy) - { - // Could also do the duck cast in the method signature, but this avoids the allocation in the instrumentation - // if not enabled. - var loggingConfigurationProxy = loggingConfiguration.DuckCast(); - if (loggingConfigurationProxy.ConfiguredNamedTargets is not null) - { - foreach (var target in loggingConfigurationProxy.ConfiguredNamedTargets) - { - if (target is IDuckType { Instance: DirectSubmissionNLogTarget }) - { - // already added - return; - } - } - } - - // need to add the new target to the logging configuraiton - loggingConfigurationProxy.AddTarget(NLogConstants.DatadogTargetName, targetProxy); - loggingConfigurationProxy.AddRuleForAllLevels(targetProxy, "**", final: true); - - Log.Information("Direct log submission via NLog 4.5+ enabled"); - } - - // internal for testing - internal static void AddDatadogTargetNLog43To45(object loggingConfiguration, object targetProxy) - { - // Could also do the duck cast in the method signature, but this avoids the allocation in the instrumentation - // if not enabled. - var loggingConfigurationProxy = loggingConfiguration.DuckCast(); - if (loggingConfigurationProxy.ConfiguredNamedTargets is not null) - { - foreach (var target in loggingConfigurationProxy.ConfiguredNamedTargets) - { - if (target is IDuckType { Instance: DirectSubmissionNLogLegacyTarget }) - { - // already added - return; - } - } - } - - // need to add the new target to the logging configuraiton - loggingConfigurationProxy.AddTarget(NLogConstants.DatadogTargetName, targetProxy); - loggingConfigurationProxy.AddRuleForAllLevels(targetProxy, "**"); - - Log.Information("Direct log submission via NLog 4.3-4.5 enabled"); - } - - // internal for testing - internal static void AddDatadogTargetNLogPre43(object loggingConfiguration, object targetProxy) - { - var loggingConfigurationProxy = loggingConfiguration.DuckCast(); - - if (loggingConfigurationProxy.ConfiguredNamedTargets is not null) - { - foreach (var target in loggingConfigurationProxy.ConfiguredNamedTargets) - { - if (target is IDuckType { Instance: DirectSubmissionNLogTarget }) - { - // already added - return; - } - } - } - - if (_createLoggingRuleFunc is null) - { - // we failed on startup, so should never get to this point - return; - } - - // need to create and add the new target - loggingConfigurationProxy.AddTarget(NLogConstants.DatadogTargetName, targetProxy); - - // Have to create a logging rule the hard way - var instance = _createLoggingRuleFunc(); - var ruleProxy = instance.DuckCast(); - - ruleProxy.LoggerNamePattern = "**"; - ruleProxy.Targets.Add(targetProxy); - for (var i = 0; i < 6; i++) - { - ruleProxy.LogLevels[i] = true; - } - - ruleProxy.Final = true; - loggingConfigurationProxy.LoggingRules.Add(instance); - - Log.Information("Direct log submission via NLog <4.3 enabled"); - } - - // internal for testing - internal static object CreateNLogTargetProxy(DirectSubmissionNLogTarget target) - { - if (_targetType is null) - { - ThrowHelper.ThrowNullReferenceException($"{nameof(_targetType)} is null"); - } - - // create a new instance of DirectSubmissionNLogTarget - var reverseProxy = target.DuckImplement(_targetType); - var targetProxy = reverseProxy.DuckCast(); - target.SetBaseProxy(targetProxy); - // theoretically this should be called per logging configuration - // but we don't need to so hack in the call here - targetProxy.Initialize(null); - return reverseProxy; - } - - // internal for testing - internal static object CreateNLogTargetProxy(DirectSubmissionNLogLegacyTarget target) - { - if (_targetType is null) - { - ThrowHelper.ThrowNullReferenceException($"{nameof(_targetType)} is null"); - } - - var reverseProxy = target.DuckImplement(_targetType); - if (_hasMappedDiagnosticsContext || _hasMappedDiagnosticsLogicalContext) - { - target.SetGetContextPropertiesFunc(() => GetContextProperties()); - } - - var targetProxy = reverseProxy.DuckCast(); - // theoretically this should be called per logging configuration - // but we don't need to so hack in the call here - targetProxy.Initialize(null); - - return reverseProxy; - } - - // internal for testing - internal static void TryGetMdcProxy( - Assembly nlogAssembly, - out bool haveMdcProxy, - out bool isModernMdcProxy, - out MappedDiagnosticsProxy? mdc, - out MappedDiagnosticsContextLegacyProxy mdcLegacy) - { - var mdcType = nlogAssembly.GetType("NLog.MappedDiagnosticsContext"); - if (mdcType is not null) - { - var createTypeResult = DuckType.GetOrCreateProxyType(typeof(MappedDiagnosticsProxy), mdcType); - if (createTypeResult.Success) - { - mdc = createTypeResult.CreateInstance(instance: null); - mdcLegacy = default; - haveMdcProxy = true; - isModernMdcProxy = true; - return; - } - - var createLegacyTypeResult = DuckType.GetOrCreateProxyType(typeof(MappedDiagnosticsContextLegacyProxy), mdcType); - if (createLegacyTypeResult.Success) - { - mdcLegacy = createLegacyTypeResult.CreateInstance(instance: null); - mdc = default; - haveMdcProxy = true; - isModernMdcProxy = false; - return; - } - } - - haveMdcProxy = false; - isModernMdcProxy = false; - mdcLegacy = default; - mdc = default; - } - - // internal for testing - internal static void TryGetMdlcProxy( - Assembly nlogAssembly, - out bool haveMdlcProxy, - out bool isModernMdlcProxy, - out MappedDiagnosticsProxy? mdlc, - out MappedDiagnosticsLogicalContextLegacyProxy mdlcLegacy) - { - var mdclType = nlogAssembly.GetType("NLog.MappedDiagnosticsLogicalContext"); - if (mdclType is not null) - { - var createTypeResult = DuckType.GetOrCreateProxyType(typeof(MappedDiagnosticsProxy), mdclType); - if (createTypeResult.Success) - { - mdlc = createTypeResult.CreateInstance(instance: null); - mdlcLegacy = default; - haveMdlcProxy = true; - isModernMdlcProxy = true; - return; - } - - var createLegacyTypeResult = DuckType.GetOrCreateProxyType(typeof(MappedDiagnosticsLogicalContextLegacyProxy), mdclType); - if (createLegacyTypeResult.Success) - { - mdlcLegacy = createLegacyTypeResult.CreateInstance(instance: null); - mdlc = null; - haveMdlcProxy = true; - isModernMdlcProxy = false; - return; - } - } - - mdlc = null; - mdlcLegacy = default; - haveMdlcProxy = false; - isModernMdlcProxy = false; - } - - // internal for testing - internal static Func CreateLoggingRuleActivator(Assembly nlogAssembly) - { - var loggingRuleType = nlogAssembly.GetType("NLog.Config.LoggingRule"); - var ctor = loggingRuleType!.GetConstructor(Type.EmptyTypes)!; // Nullable YOLO - - DynamicMethod createLoggingRuleMethod = new DynamicMethod( - $"NLogCommon_CreateLoggingRuleActivator", - loggingRuleType, - null, - typeof(DuckType).Module, - true); - - ILGenerator il = createLoggingRuleMethod.GetILGenerator(); - il.Emit(OpCodes.Newobj, ctor); - il.Emit(OpCodes.Ret); - - return (Func)createLoggingRuleMethod.CreateDelegate(typeof(Func)); - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/NLogConstants.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/NLogConstants.cs deleted file mode 100644 index 3c2d6cff3..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/NLogConstants.cs +++ /dev/null @@ -1,16 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using Datadog.Trace.Configuration; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission -{ - internal static class NLogConstants - { - internal const string DatadogTargetName = "Datadog"; - - internal const string IntegrationName = nameof(IntegrationId.NLog); - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILogEventInfoLegacyProxy.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILogEventInfoLegacyProxy.cs deleted file mode 100644 index cf8044ae1..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILogEventInfoLegacyProxy.cs +++ /dev/null @@ -1,23 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Collections.Generic; -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies -{ - /// - /// Duck type for LogEventInfo for NLog < 4.5 - /// Using virtual members, as will need to be boxed, so no advantage from using a struct - /// - internal interface ILogEventInfoLegacyProxy : ILogEventInfoProxyBase - { - /// - /// Gets the dictionary of per-event context properties - /// - [DuckField(Name = "properties")] - public IDictionary Properties { get; } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILogEventInfoProxy.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILogEventInfoProxy.cs deleted file mode 100644 index 25a37c2c9..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILogEventInfoProxy.cs +++ /dev/null @@ -1,26 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Collections.Generic; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies -{ - /// - /// Duck type for LogEventInfo for NLog > 4.5 - /// Using virtual members, as will need to be boxed, so no advantage from using a struct - /// - internal interface ILogEventInfoProxy : ILogEventInfoProxyBase - { - /// - /// Gets a value indicating whether there are any per-event properties (Without allocation) - /// - public bool HasProperties { get; } - - /// - /// Gets the dictionary of per-event context properties - /// - public IDictionary Properties { get; } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILogEventInfoProxyBase.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILogEventInfoProxyBase.cs deleted file mode 100644 index 598f71d72..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILogEventInfoProxyBase.cs +++ /dev/null @@ -1,42 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies -{ - /// - /// Duck type for LogEventInfo for NLog < 4.5 - /// Using interface members, as will need to be boxed, so no advantage from using a struct - /// - internal interface ILogEventInfoProxyBase - { - /// - /// Gets the timestamp - /// - public DateTime TimeStamp { get; } - - /// - /// Gets the log level - /// - public LogLevelProxy Level { get; } - - /// - /// Gets the exception - /// - public Exception Exception { get; } - - /// - /// Gets the formatted message. - /// - public string FormattedMessage { get; } - - /// - /// Gets the log message including any parameter placeholders. - /// - public string Message { get; } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILoggingConfigurationLegacyProxy.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILoggingConfigurationLegacyProxy.cs deleted file mode 100644 index d0ac894d3..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILoggingConfigurationLegacyProxy.cs +++ /dev/null @@ -1,37 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Collections; -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies -{ - /// - /// Duck type for LoggingConfiguration for NLog > 4.3-4.5 - /// - internal interface ILoggingConfigurationLegacyProxy - { - /// - /// Gets a collection of named targets specified in the configuration. - /// - public IEnumerable ConfiguredNamedTargets { get; } - - /// - /// Registers the specified target object under a given name. - /// - /// Name of the target. - /// The target object. - [Duck(ParameterTypeNames = new[] { ClrNames.String, "NLog.Targets.Target, NLog" })] - public void AddTarget(string name, object target); - - /// - /// Add a rule for all loglevels. - /// - /// Target to be written to when the rule matches. - /// Logger name pattern. It may include the '*' wildcard at the beginning, at the end or at both ends. - [Duck(ParameterTypeNames = new[] { "NLog.Targets.Target, NLog", ClrNames.String })] - public void AddRuleForAllLevels(object target, string loggerNamePattern); - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILoggingConfigurationProxy.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILoggingConfigurationProxy.cs deleted file mode 100644 index 4d4f3836e..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ILoggingConfigurationProxy.cs +++ /dev/null @@ -1,38 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Collections; -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies -{ - /// - /// Duck type for LoggingConfiguration for NLog 4.5+ - /// - internal interface ILoggingConfigurationProxy - { - /// - /// Gets a collection of named targets specified in the configuration. - /// - public IEnumerable ConfiguredNamedTargets { get; } - - /// - /// Registers the specified target object under a given name. - /// - /// Name of the target. - /// The target object. - [Duck(ParameterTypeNames = new[] { ClrNames.String, "NLog.Targets.Target, NLog" })] - public void AddTarget(string name, object target); - - /// - /// Add a rule for all loglevels. - /// - /// Target to be written to when the rule matches. - /// Logger name pattern. It may include the '*' wildcard at the beginning, at the end or at both ends. - /// Gets or sets a value indicating whether to quit processing any further rule when this one matches. - [Duck(ParameterTypeNames = new[] { "NLog.Targets.Target, NLog", ClrNames.String, ClrNames.Bool })] - public void AddRuleForAllLevels(object target, string loggerNamePattern, bool final); - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ITargetProxy.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ITargetProxy.cs deleted file mode 100644 index 27f1fed2d..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ITargetProxy.cs +++ /dev/null @@ -1,23 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies -{ - /// - /// Duck type for TargetWithContext - /// Represents target that supports context capture using MDLC, MDC, NDLC and NDC - /// - internal interface ITargetProxy - { - /// - /// Initializes this instance. - /// - /// The configuration. - [Duck(ExplicitInterfaceTypeName = "NLog.Internal.ISupportsInitialize", ParameterTypeNames = new[] { "NLog.Config.LoggingConfiguration" })] - public void Initialize(object configuration); - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ITargetWithContextBaseProxy.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ITargetWithContextBaseProxy.cs deleted file mode 100644 index 92754dca1..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/ITargetWithContextBaseProxy.cs +++ /dev/null @@ -1,60 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Collections.Generic; -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies -{ - /// - /// Duck type for TargetWithContext - /// Represents target that supports context capture using MDLC, MDC, NDLC and NDC - /// - internal interface ITargetWithContextBaseProxy - { - /// - /// Gets or sets a value indicating whether gets or sets the option to include all properties from the log events - /// - public bool IncludeEventProperties { get; set; } - - /// - /// Gets or sets a value indicating whether to include contents of the MappedDiagnosticsContext dictionary. - /// - /// - public bool IncludeMdc { get; set; } - - /// - /// Gets or sets a value indicating whether to include contents of the NestedDiagnosticsContext stack. - /// - /// - public bool IncludeNdc { get; set; } - - /// - /// Gets or sets a value indicating whether to include contents of the MappedDiagnosticsLogicalContext dictionary. - /// - /// - public bool IncludeMdlc { get; set; } - - /// - /// Gets or sets a value indicating whether to include contents of the NestedDiagnosticsLogicalContext stack. - /// - /// - public bool IncludeNdlc { get; set; } - - /// - /// Creates combined dictionary of all configured properties for logEvent - /// - /// The event to record - /// Dictionary with all collected properties for logEvent - public IDictionary GetAllProperties(ILogEventInfoProxy logEvent); - - /// - /// Initializes this instance. - /// - /// The configuration. - [Duck(ExplicitInterfaceTypeName = "NLog.Internal.ISupportsInitialize", ParameterTypeNames = new[] { "NLog.Config.LoggingConfiguration" })] - public void Initialize(object configuration); - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/LogLevelProxy.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/LogLevelProxy.cs deleted file mode 100644 index ef11be6a4..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/LogLevelProxy.cs +++ /dev/null @@ -1,21 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies -{ - /// - /// Duck type for LogLevel - /// - [DuckCopy] - internal struct LogLevelProxy - { - /// - /// Gets the name of the log level - /// - public int Ordinal; - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/MappedDiagnosticsContextLegacyProxy.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/MappedDiagnosticsContextLegacyProxy.cs deleted file mode 100644 index 50bdf47a4..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/MappedDiagnosticsContextLegacyProxy.cs +++ /dev/null @@ -1,24 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Collections; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies -{ - /// - /// Duck type for MappedDiagnosticsContextProxy for NLog < 4.3 - /// Mapped Diagnostics Context - a thread-local structure that keeps a dictionary - /// of strings and provides methods to output them in layouts. - /// - internal struct MappedDiagnosticsContextLegacyProxy - { - /// - /// Gets the thread local dictionary for the type - /// Using an IDictionary instead of typed as in 4.0.x this is a (string, string), - /// and in later versions it's a (string, object) - /// - public IDictionary ThreadDictionary; - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/MappedDiagnosticsLogicalContextLegacyProxy.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/MappedDiagnosticsLogicalContextLegacyProxy.cs deleted file mode 100644 index cdd2022da..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/MappedDiagnosticsLogicalContextLegacyProxy.cs +++ /dev/null @@ -1,23 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Collections; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies -{ - /// - /// Duck type for MappedDiagnosticsLogicalContext in NLog <4.3 - /// Async version of Mapped Diagnostics Context - a logical context structure that keeps a dictionary - /// of strings and provides methods to output them in layouts. Allows for maintaining state across - /// asynchronous tasks and call contexts. - /// - internal struct MappedDiagnosticsLogicalContextLegacyProxy - { - /// - /// Gets the async local dictionary for the type - /// - public IDictionary LogicalThreadDictionary; - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/MappedDiagnosticsProxy.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/MappedDiagnosticsProxy.cs deleted file mode 100644 index 86727bae6..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/MappedDiagnosticsProxy.cs +++ /dev/null @@ -1,35 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Collections.Generic; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies -{ - /// - /// Duck type for MappedDiagnosticsContext and MappedDiagnosticsLogicalContext in NLog 4.3+ - /// Async version of Mapped Diagnostics Context - a logical context structure that keeps a dictionary - /// of strings and provides methods to output them in layouts. Allows for maintaining state across - /// asynchronous tasks and call contexts. - /// -#pragma warning disable SA1400 -#pragma warning disable SA1302 - internal interface MappedDiagnosticsProxy -#pragma warning restore SA1302 -#pragma warning restore SA1400 - { - /// - /// Gets the item names - /// - /// A collection of the names of all items in current logical context. - public ICollection GetNames(); - - /// - /// Gets the current logical context named item, as - /// - /// Item name - /// The value of , if defined; otherwise null. - public object GetObject(string item); - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/Pre43/ILoggingConfigurationPre43Proxy.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/Pre43/ILoggingConfigurationPre43Proxy.cs deleted file mode 100644 index cd695204f..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/Pre43/ILoggingConfigurationPre43Proxy.cs +++ /dev/null @@ -1,34 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Collections; -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies.Pre43 -{ - /// - /// Duck type for LoggingConfiguration for NLog < 4.3 - /// - internal interface ILoggingConfigurationPre43Proxy - { - /// - /// Gets a collection of named targets specified in the configuration. - /// - public IEnumerable ConfiguredNamedTargets { get; } - - /// - /// Gets the collection of logging rules - /// - public ILoggingRulesListProxy LoggingRules { get; } - - /// - /// Registers the specified target object under a given name. - /// - /// Name of the target. - /// The target object. - [Duck(ParameterTypeNames = new[] { ClrNames.String, "NLog.Targets.Target, NLog" })] - public void AddTarget(string name, object target); - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/Pre43/ILoggingRuleProxy.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/Pre43/ILoggingRuleProxy.cs deleted file mode 100644 index c588accd5..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/Pre43/ILoggingRuleProxy.cs +++ /dev/null @@ -1,38 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies.Pre43 -{ - /// - /// Duck type for LoggingRule for NLog < 4.3 - /// This is left as an interface instead of a [DuckCopy] struct as we need to - /// set values on the proxy too. - /// - internal interface ILoggingRuleProxy - { - /// - /// Gets or sets logger name pattern - /// - public string LoggerNamePattern { get; set; } - - /// - /// Gets the collection of logging rules - /// - public ITargetListProxy Targets { get; } - - /// - /// Gets or sets a value indicating whether to quit processing any further rule when this one matches - /// - public bool Final { get; set; } - - /// - /// Gets the loglevels - /// - [DuckField(Name = "logLevels")] - public bool[] LogLevels { get; } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/Pre43/ILoggingRulesListProxy.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/Pre43/ILoggingRulesListProxy.cs deleted file mode 100644 index 0d3985d45..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/Pre43/ILoggingRulesListProxy.cs +++ /dev/null @@ -1,23 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.ComponentModel; -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies.Pre43 -{ - /// - /// Duck type for IList<LoggingRule> - /// - internal interface ILoggingRulesListProxy - { - /// - /// Adds the logging rule to the collection - /// - /// The logging rule to add to the collection - [Duck(ParameterTypeNames = new[] { "NLog.Config.LoggingRule, NLog" })] - public void Add(object item); - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/Pre43/ITargetListProxy.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/Pre43/ITargetListProxy.cs deleted file mode 100644 index afdafbcdf..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/Proxies/Pre43/ITargetListProxy.cs +++ /dev/null @@ -1,22 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies.Pre43 -{ - /// - /// Duck type for IList<LoggingRule> - /// - internal interface ITargetListProxy - { - /// - /// Adds the logging rule to the collection - /// - /// The logging rule to add to the collection - [Duck(ParameterTypeNames = new[] { "NLog.Targets.Target, NLog" })] - public void Add(object item); - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/DirectSubmissionSerilogSink.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/DirectSubmissionSerilogSink.cs deleted file mode 100644 index 336e2634d..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/DirectSubmissionSerilogSink.cs +++ /dev/null @@ -1,47 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Sink; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission -{ - /// - /// Serilog Sink - /// - internal class DirectSubmissionSerilogSink - { - private readonly IDatadogSink _sink; - private readonly int _minimumLevel; - - internal DirectSubmissionSerilogSink(IDatadogSink sink, DirectSubmissionLogLevel minimumLevel) - { - _sink = sink; - _minimumLevel = (int)minimumLevel; - } - - /// - /// Emit the provided log event to the sink - /// - /// The log event to write. - [DuckReverseMethod(ParameterTypeNames = new[] { "Serilog.Events.LogEvent, Serilog" })] - public void Emit(ILogEvent? logEvent) - { - if (logEvent is null) - { - return; - } - - if ((int)logEvent.Level < _minimumLevel) - { - return; - } - - _sink.EnqueueLog(new SerilogDatadogLogEvent(logEvent)); - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/DictionaryValueDuck.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/DictionaryValueDuck.cs deleted file mode 100644 index 0fedd65a0..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/DictionaryValueDuck.cs +++ /dev/null @@ -1,23 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Collections; -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.Formatting -{ - /// - /// Duck type for DictionaryValue - /// https://github.dev/serilog/serilog/blob/5e93d5045585095ebcb71ef340d6accd61f01670/src/Serilog/Events/DictionaryValue.cs - /// - [DuckCopy] - internal struct DictionaryValueDuck - { - /// - /// Gets the properties associated with the structure - /// - public IEnumerable Elements; - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/KeyValuePairObjectStruct.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/KeyValuePairObjectStruct.cs deleted file mode 100644 index 8225421c5..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/KeyValuePairObjectStruct.cs +++ /dev/null @@ -1,26 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.Formatting -{ - /// - /// Duck type for KeyValuePair<object, LogEventPropertyValue> - /// - [DuckCopy] - internal struct KeyValuePairObjectStruct - { - /// - /// Gets the key - /// - public object Key; - - /// - /// Gets the value (A LogEventPropertyValue (ScalarValue/StructureValue etc) - /// - public object Value; - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/KeyValuePairStringStruct.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/KeyValuePairStringStruct.cs deleted file mode 100644 index aad1e1dc9..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/KeyValuePairStringStruct.cs +++ /dev/null @@ -1,26 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.Formatting -{ - /// - /// Duck type for KeyValuePair<object, LogEventPropertyValue> - /// - [DuckCopy] - internal struct KeyValuePairStringStruct - { - /// - /// Gets the key - /// - public string Key; - - /// - /// Gets the value (A LogEventPropertyValue (ScalarValue/StructureValue etc) - /// - public object Value; - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/LogEventPropertyDuck.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/LogEventPropertyDuck.cs deleted file mode 100644 index 29b31faa9..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/LogEventPropertyDuck.cs +++ /dev/null @@ -1,27 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.Formatting -{ - /// - /// Duck type for LogEventProperty - /// https://github.dev/serilog/serilog/blob/5e93d5045585095ebcb71ef340d6accd61f01670/src/Serilog/Events/LogEventProperty.cs - /// - [DuckCopy] - internal struct LogEventPropertyDuck - { - /// - /// Gets the name - /// - public string Name; - - /// - /// Gets the value - /// - public object Value; - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/ScalarValueDuck.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/ScalarValueDuck.cs deleted file mode 100644 index 4fe6a84f3..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/ScalarValueDuck.cs +++ /dev/null @@ -1,22 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.Formatting -{ - /// - /// Duck type for ScalarValue - /// https://github.com/serilog/serilog/blob/5e93d5045585095ebcb71ef340d6accd61f01670/src/Serilog/Events/ScalarValue.cs - /// - [DuckCopy] - internal struct ScalarValueDuck - { - /// - /// Gets the value - /// - public object Value; - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/SequenceValueDuck.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/SequenceValueDuck.cs deleted file mode 100644 index ae34a4b74..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/SequenceValueDuck.cs +++ /dev/null @@ -1,24 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.Formatting -{ - /// - /// Duck type for SequenceValue - /// https://github.dev/serilog/serilog/blob/5e93d5045585095ebcb71ef340d6accd61f01670/src/Serilog/Events/SequenceValue.cs - /// - [DuckCopy] - internal struct SequenceValueDuck - { - /// - /// Gets the sequence values - /// - [DuckField(Name = "_elements")] - public Array Elements; - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/SerilogLogFormatter.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/SerilogLogFormatter.cs deleted file mode 100644 index b9ae96d4a..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/SerilogLogFormatter.cs +++ /dev/null @@ -1,162 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System.Collections; -using System.Text; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Vendors.Newtonsoft.Json; -using Datadog.Trace.Vendors.Serilog.Events; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.Formatting -{ - internal static class SerilogLogFormatter - { - private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(typeof(SerilogLogFormatter)); - - public static void FormatLogEvent(LogFormatter logFormatter, StringBuilder sb, ILogEvent logEvent) - { - var message = logEvent.RenderMessage(); - - logFormatter.FormatLog( - sb, - logEvent, - logEvent.Timestamp.UtcDateTime, - message, - eventId: null, - GetLogLevelString(logEvent.Level), - logEvent.Exception, - (JsonTextWriter w, in ILogEvent e) => RenderProperties(w, e)); - } - - private static string GetLogLevelString(LogEventLevelDuck logLevel) => - logLevel switch - { - LogEventLevelDuck.Verbose => DirectSubmissionLogLevelExtensions.Verbose, - LogEventLevelDuck.Debug => DirectSubmissionLogLevelExtensions.Debug, - LogEventLevelDuck.Information => DirectSubmissionLogLevelExtensions.Information, - LogEventLevelDuck.Warning => DirectSubmissionLogLevelExtensions.Warning, - LogEventLevelDuck.Error => DirectSubmissionLogLevelExtensions.Error, - LogEventLevelDuck.Fatal => DirectSubmissionLogLevelExtensions.Fatal, - _ => DirectSubmissionLogLevelExtensions.Unknown, - }; - - private static LogPropertyRenderingDetails RenderProperties(JsonTextWriter writer, in ILogEvent logEvent) - { - var haveSource = false; - var haveService = false; - var haveHost = false; - var haveTags = false; - var haveEnv = false; - var haveVersion = false; - foreach (var property in logEvent.Properties) - { - var duckProperty = property.DuckCast(); - var name = duckProperty.Key; - - haveSource |= LogFormatter.IsSourceProperty(name); - haveService |= LogFormatter.IsServiceProperty(name); - haveHost |= LogFormatter.IsHostProperty(name); - haveTags |= LogFormatter.IsTagsProperty(name); - haveEnv |= LogFormatter.IsEnvProperty(name); - haveVersion |= LogFormatter.IsVersionProperty(name); - - LogFormatter.WritePropertyName(writer, name); - FormatLogEventPropertyValue(writer, duckProperty.Value); - } - - return new LogPropertyRenderingDetails( - hasRenderedSource: haveSource, - hasRenderedService: haveService, - hasRenderedHost: haveHost, - hasRenderedTags: haveTags, - hasRenderedEnv: haveEnv, - hasRenderedVersion: haveVersion, - messageTemplate: logEvent.MessageTemplate.Text); - } - - private static void FormatLogEventPropertyValue(JsonTextWriter writer, object value) - { - // format the value correctly depending on type - if (value.TryDuckCast(out var scalar)) - { - LogFormatter.WriteValue(writer, scalar.Value); - return; - } - - if (value.TryDuckCast(out var sequence)) - { - FormatSequence(writer, sequence.Elements); - return; - } - - if (value.TryDuckCast(out var structure)) - { - FormatStructure(writer, structure.Properties, structure.TypeTag); - return; - } - - if (value.TryDuckCast(out var dictionary)) - { - FormatDictionary(writer, dictionary.Elements); - return; - } - - if (Log.IsEnabled(LogEventLevel.Debug)) - { - Log.Debug($"Unknown Serilog LogEventPropertyValue '{value.GetType()}': skipping in log message"); - LogFormatter.WriteValue(writer, value: null); - } - } - - private static void FormatSequence(JsonTextWriter writer, IEnumerable properties) - { - writer.WriteStartArray(); - foreach (var property in properties) - { - FormatLogEventPropertyValue(writer, property!); - } - - writer.WriteEndArray(); - } - - private static void FormatStructure(JsonTextWriter writer, IEnumerable properties, string typeTag) - { - writer.WriteStartObject(); - - foreach (var property in properties) - { - var duck = property.DuckCast(); - writer.WritePropertyName(duck.Name); - FormatLogEventPropertyValue(writer, duck.Value); - } - - if (!string.IsNullOrEmpty(typeTag)) - { - writer.WritePropertyName("_typeTag"); - writer.WriteValue(typeTag); - } - - writer.WriteEndObject(); - } - - private static void FormatDictionary(JsonTextWriter writer, IEnumerable properties) - { - writer.WriteStartObject(); - - foreach (var property in properties) - { - var duck = property.DuckCast(); - writer.WritePropertyName(duck.Key?.ToString() ?? "null"); - FormatLogEventPropertyValue(writer, duck.Value); - } - - writer.WriteEndObject(); - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/StructureValueDuck.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/StructureValueDuck.cs deleted file mode 100644 index c50e04826..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/Formatting/StructureValueDuck.cs +++ /dev/null @@ -1,29 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Collections; -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.Formatting -{ - /// - /// Duck type for ScalarValue - /// https://github.dev/serilog/serilog/blob/5e93d5045585095ebcb71ef340d6accd61f01670/src/Serilog/Events/ScalarValue.cs - /// - [DuckCopy] - internal struct StructureValueDuck - { - /// - /// Gets the properties associated with the structure - /// These are convertible to - /// - public IEnumerable Properties; - - /// - /// Gets the type of the structure - /// - public string TypeTag; - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/ILogEvent.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/ILogEvent.cs deleted file mode 100644 index 2b0429af3..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/ILogEvent.cs +++ /dev/null @@ -1,50 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Collections; -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission -{ - /// - /// Duck type for LogEvent - /// - internal interface ILogEvent : IDuckType - { - /// - /// Gets the time at which the event occurred. - /// - public DateTimeOffset Timestamp { get; } - - /// - /// Gets the level of the event. - /// - public LogEventLevelDuck Level { get; } - - /// - /// Gets the message template describing the event. - /// - public MessageTemplateProxy MessageTemplate { get; } - - /// - /// Gets properties associated with the event, including those presented in . - /// - public IEnumerable Properties { get; } - - /// - /// Gets an exception associated with the event, or null. - /// - public Exception Exception { get; } - - /// - /// Render the message template given the properties associated - /// with the event, and return the result. - /// - /// Supplies culture-specific formatting information, or null. - /// The rendered message - public string RenderMessage(IFormatProvider formatProvider = null); - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/ILoggerConfiguration.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/ILoggerConfiguration.cs deleted file mode 100644 index 9a595159a..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/ILoggerConfiguration.cs +++ /dev/null @@ -1,23 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Collections; -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission -{ - /// - /// Duck typing for LoggerConfiguration - /// Interface, as used in instrumentation constraint - /// - internal interface ILoggerConfiguration - { - /// - /// Gets the - /// - [DuckField(Name = "_logEventSinks")] - public IList LogEventSinks { get; } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/LogEventLevelDuck.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/LogEventLevelDuck.cs deleted file mode 100644 index ab1ff155b..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/LogEventLevelDuck.cs +++ /dev/null @@ -1,48 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission -{ - /// - /// Duck type for LogEventLevel - /// - internal enum LogEventLevelDuck - { - /// - /// Anything and everything you might want to know about - /// a running block of code. - /// - Verbose, - - /// - /// Internal system events that aren't necessarily - /// observable from the outside. - /// - Debug, - - /// - /// The lifeblood of operational intelligence - things - /// happen. - /// - Information, - - /// - /// Service is degraded or endangered. - /// - Warning, - - /// - /// Functionality is unavailable, invariants are broken - /// or data is lost. - /// - Error, - - /// - /// If you have a pager, it goes off when one of these - /// occurs. - /// - Fatal - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/LoggerConfigurationInstrumentation.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/LoggerConfigurationInstrumentation.cs deleted file mode 100644 index 511cf6d50..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/LoggerConfigurationInstrumentation.cs +++ /dev/null @@ -1,85 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System.ComponentModel; -using Datadog.Trace.ClrProfiler.CallTarget; -using Datadog.Trace.Configuration; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission -{ - /// - /// LoggerConfiguration.CreateLogger() calltarget instrumentation - /// - [InstrumentMethod( - AssemblyName = "Serilog", - TypeName = "Serilog.LoggerConfiguration", - MethodName = "CreateLogger", - ReturnTypeName = "Serilog.Core.Logger", - ParameterTypeNames = new string[0], - MinimumVersion = "1.0.0", - MaximumVersion = "2.*.*", - IntegrationName = nameof(IntegrationId.Serilog))] - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public class LoggerConfigurationInstrumentation - { - private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(); - - /// - /// OnMethodBegin callback - /// - /// Type of the target - /// Instance value, aka `this` of the instrumented method. - /// Calltarget state value - internal static CallTargetState OnMethodBegin(TTarget instance) - where TTarget : ILoggerConfiguration, IDuckType - { - if (TracerManager.Instance.DirectLogSubmission.Settings.IsIntegrationEnabled(IntegrationId.Serilog)) - { - TryAddSink(instance); - } - - return CallTargetState.GetDefault(); - } - - private static void TryAddSink(TTarget instance) - where TTarget : ILoggerConfiguration, IDuckType - { - var sinkAlreadyAdded = false; - - // if we've already added the sink, nothing more to do. - foreach (var logEventSink in instance.LogEventSinks) - { - if (logEventSink is DirectSubmissionSerilogSink - || logEventSink?.GetType().FullName == "Serilog.Sinks.Datadog.Logs.DatadogSink") - { - sinkAlreadyAdded = true; - break; - } - } - - if (!sinkAlreadyAdded) - { - var targetType = instance.Type.Assembly.GetType("Serilog.Core.ILogEventSink"); - if (targetType is null) - { - Log.Error("Serilog.Core.ILogEventSink type cannot be found."); - return; - } - - var sink = new DirectSubmissionSerilogSink( - TracerManager.Instance.DirectLogSubmission.Sink, - TracerManager.Instance.DirectLogSubmission.Settings.MinimumLevel); - - var proxy = sink.DuckImplement(targetType); - instance.LogEventSinks.Add(proxy); - Log.Information("Direct log submission via Serilog enabled"); - } - } - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/MessageTemplateProxy.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/MessageTemplateProxy.cs deleted file mode 100644 index d9f1dbaff..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/MessageTemplateProxy.cs +++ /dev/null @@ -1,21 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using Datadog.Trace.DuckTyping; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission -{ - /// - /// Duck typing for MessageTemplate - /// - [DuckCopy] - internal struct MessageTemplateProxy - { - /// - /// Gets the raw text describing the template - /// - public string Text; - } -} diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/SerilogDatadogLogEvent.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/SerilogDatadogLogEvent.cs deleted file mode 100644 index 740d2fe79..000000000 --- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Serilog/DirectSubmission/SerilogDatadogLogEvent.cs +++ /dev/null @@ -1,28 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System.Text; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink; - -namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission -{ - internal class SerilogDatadogLogEvent : DatadogLogEvent - { - private readonly ILogEvent _logEvent; - - public SerilogDatadogLogEvent(ILogEvent logEvent) - { - _logEvent = logEvent; - } - - public override void Format(StringBuilder sb, LogFormatter formatter) - { - SerilogLogFormatter.FormatLogEvent(formatter, sb, _logEvent); - } - } -} diff --git a/tracer/src/Datadog.Trace/Configuration/ConfigurationKeys.DirectLogSubmission.cs b/tracer/src/Datadog.Trace/Configuration/ConfigurationKeys.DirectLogSubmission.cs deleted file mode 100644 index 3794c797d..000000000 --- a/tracer/src/Datadog.Trace/Configuration/ConfigurationKeys.DirectLogSubmission.cs +++ /dev/null @@ -1,86 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using Datadog.Trace.Logging.DirectSubmission; - -namespace Datadog.Trace.Configuration -{ - internal static partial class ConfigurationKeys - { - internal static class DirectLogSubmission - { - /// - /// Configuration key for a list of direct log submission integrations to enable. - /// Only selected integrations are enabled for direct log submission - /// Default is empty (direct log submission disabled). - /// Supports multiple values separated with semi-colons. - /// - /// - public const string EnabledIntegrations = "SIGNALFX_LOGS_DIRECT_SUBMISSION_INTEGRATIONS"; - - /// - /// Set the name of the originating host for direct logs submission. - /// Required for direct logs submission (default is machine name). - /// - /// - public const string Host = "SIGNALFX_LOGS_DIRECT_SUBMISSION_HOST"; - - /// - /// Set the originating source for direct logs submission. - /// Default is 'csharp' - /// - /// - public const string Source = "SIGNALFX_LOGS_DIRECT_SUBMISSION_SOURCE"; - - /// - /// Configuration key for a list of tags to be applied globally to all logs directly submitted. - /// Supports multiple key key-value pairs which are comma-separated, and for which the key and - /// value are colon-separated. For example Key1:Value1, Key2:Value2. If not provided, - /// are used instead - /// - /// - public const string GlobalTags = "SIGNALFX_LOGS_DIRECT_SUBMISSION_TAGS"; - - /// - /// Configuration key for the url to send logs to. - /// Default value uses the domain set in , so defaults to - /// https://http-intake.logs.datadoghq.com:443. - /// - /// - public const string Url = "SIGNALFX_LOGS_DIRECT_SUBMISSION_URL"; - - /// - /// Configuration key for the minimum level logs should have to be sent to the intake. - /// Default value is Information. - /// Should be one of Verbose,Debug,Information,Warning,Error,Fatal - /// - /// - public const string MinimumLevel = "SIGNALFX_LOGS_DIRECT_SUBMISSION_MINIMUM_LEVEL"; - - /// - /// Configuration key for the maximum number of logs to send at one time - /// Default value is 1,000, the maximum accepted by the Datadog log API - /// - /// - public const string BatchSizeLimit = "SIGNALFX_LOGS_DIRECT_SUBMISSION_MAX_BATCH_SIZE"; - - /// - /// Configuration key for the maximum number of logs to hold in internal queue at any one time - /// Default value is 100,000. - /// - /// - public const string QueueSizeLimit = "SIGNALFX_LOGS_DIRECT_SUBMISSION_MAX_QUEUE_SIZE"; - - /// - /// Configuration key for the time to wait between checking for batches - /// Default value is 2s. - /// - /// - public const string BatchPeriodSeconds = "SIGNALFX_LOGS_DIRECT_SUBMISSION_BATCH_PERIOD_SECONDS"; - } - } -} diff --git a/tracer/src/Datadog.Trace/Configuration/ConfigurationKeys.cs b/tracer/src/Datadog.Trace/Configuration/ConfigurationKeys.cs index 5e3285110..2ada5d8e2 100644 --- a/tracer/src/Datadog.Trace/Configuration/ConfigurationKeys.cs +++ b/tracer/src/Datadog.Trace/Configuration/ConfigurationKeys.cs @@ -429,46 +429,6 @@ internal static partial class ConfigurationKeys /// public const string QueryStringReportingEnabled = "SIGNALFX_HTTP_SERVER_TAG_QUERY_STRING"; - /// - /// String constants for CI Visibility configuration keys. - /// - public static class CIVisibility - { - /// - /// Configuration key for enabling or disabling CI Visibility. - /// Default value is false (disabled). - /// - public const string Enabled = "SIGNALFX_CIVISIBILITY_ENABLED"; - - /// - /// Configuration key for enabling or disabling Agentless in CI Visibility. - /// Default value is false (disabled). - /// - public const string AgentlessEnabled = "SIGNALFX_CIVISIBILITY_AGENTLESS_ENABLED"; - - /// - /// Configuration key for setting the agentless url endpoint - /// - public const string AgentlessUrl = "SIGNALFX_CIVISIBILITY_AGENTLESS_URL"; - - /// - /// Configuration key for enabling or disabling Logs direct submission. - /// Default value is false (disabled). - /// - public const string Logs = "SIGNALFX_CIVISIBILITY_LOGS_ENABLED"; - - /// - /// Configuration key for enabling or disabling Code Coverage in CI Visibility. - /// Default value is false (disabled). - /// - public const string CodeCoverage = "SIGNALFX_CIVISIBILITY_CODE_COVERAGE_ENABLED"; - - /// - /// Configuration key for re-signing assemblies after the Code Coverage modification. - /// - public const string CodeCoverageSnkFile = "SIGNALFX_CIVISIBILITY_CODE_COVERAGE_SNK_FILEPATH"; - } - /// /// String constants for proxy configuration keys. /// @@ -583,29 +543,6 @@ internal static class AlwaysOnProfiler public const string ExportInterval = "SIGNALFX_PROFILER_EXPORT_INTERVAL"; } - internal static class Telemetry - { - /// - /// Configuration key for enabling or disabling internal telemetry. - /// Default value is true (enabled). - /// - public const string Enabled = "SIGNALFX_INSTRUMENTATION_TELEMETRY_ENABLED"; - - /// - /// Configuration key for sending telemetry direct to telemetry intake. If enabled, and - /// is set, sends telemetry direct to intake. Otherwise, sends - /// telemetry to Agent. Enabled by default if is available. - /// - public const string AgentlessEnabled = "SIGNALFX_INSTRUMENTATION_TELEMETRY_AGENTLESS_ENABLED"; - - /// - /// Configuration key for the telemetry URL where the Tracer sends telemetry. Only applies when agentless - /// telemetry is in use (otherwise telemetry is sent to the agent using - /// instead) - /// - public const string Uri = "SIGNALFX_INSTRUMENTATION_TELEMETRY_URL"; - } - internal static class TagPropagation { /// diff --git a/tracer/src/Datadog.Trace/Configuration/ImmutableTracerSettings.cs b/tracer/src/Datadog.Trace/Configuration/ImmutableTracerSettings.cs index 58f5f6f3c..18016cac9 100644 --- a/tracer/src/Datadog.Trace/Configuration/ImmutableTracerSettings.cs +++ b/tracer/src/Datadog.Trace/Configuration/ImmutableTracerSettings.cs @@ -85,7 +85,7 @@ public ImmutableTracerSettings(TracerSettings settings) ThreadSamplingPeriod = settings.ThreadSamplingPeriod; ProfilerExportInterval = CpuProfilingEnabled ? ThreadSamplingPeriod : settings.ProfilerExportInterval; - LogSubmissionSettings = ImmutableDirectLogSubmissionSettings.Create(settings.LogSubmissionSettings); + LogSubmissionSettings = ImmutableDirectLogSubmissionSettings.CreateNullSettings(); // Logs injection is enabled by default if direct log submission is enabled, otherwise disabled by default LogsInjectionEnabled = settings.LogSubmissionSettings.LogsInjectionEnabled ?? LogSubmissionSettings.IsEnabled; DebuggerSettings = ImmutableDebuggerSettings.Create(settings.DebuggerSettings); diff --git a/tracer/src/Datadog.Trace/Configuration/TracerSettings.cs b/tracer/src/Datadog.Trace/Configuration/TracerSettings.cs index 0e88bdb6e..c4264a9ef 100644 --- a/tracer/src/Datadog.Trace/Configuration/TracerSettings.cs +++ b/tracer/src/Datadog.Trace/Configuration/TracerSettings.cs @@ -312,8 +312,6 @@ public TracerSettings(IConfigurationSource source) /// /// Gets or sets a value indicating whether correlation identifiers are /// automatically injected into the logging context. - /// Default is false, unless - /// enables Direct Log Submission. /// /// public bool LogsInjectionEnabled diff --git a/tracer/src/Datadog.Trace/Generated/net461/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.InstrumentationDefinitions.InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs b/tracer/src/Datadog.Trace/Generated/net461/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.InstrumentationDefinitions.InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs index 43052a9bb..0746a0338 100644 --- a/tracer/src/Datadog.Trace/Generated/net461/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.InstrumentationDefinitions.InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs +++ b/tracer/src/Datadog.Trace/Generated/net461/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.InstrumentationDefinitions.InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs @@ -154,9 +154,6 @@ static InstrumentationDefinitions() new ("System.Net.Http.WinHttpHandler", "System.Net.Http.WinHttpHandler", "SendAsync", new[] { "System.Threading.Tasks.Task`1", "System.Net.Http.HttpRequestMessage", "System.Threading.CancellationToken" }, 4, 0, 0, 7, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Http.HttpClient.WinHttpHandler.WinHttpHandlerIntegration"), // ILogger - new ("Microsoft.Extensions.Logging", "Microsoft.Extensions.Logging.LoggerFactory", ".ctor", new[] { "System.Void", "System.Collections.Generic.IEnumerable`1[Microsoft.Extensions.Logging.ILoggerProvider]", "Microsoft.Extensions.Options.IOptionsMonitor`1[Microsoft.Extensions.Logging.LoggerFilterOptions]" }, 2, 0, 0, 3, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration"), - new ("Microsoft.Extensions.Logging", "Microsoft.Extensions.Logging.LoggerFactory", ".ctor", new[] { "System.Void", "System.Collections.Generic.IEnumerable`1[Microsoft.Extensions.Logging.ILoggerProvider]", "Microsoft.Extensions.Options.IOptionsMonitor`1[Microsoft.Extensions.Logging.LoggerFilterOptions]", "Microsoft.Extensions.Options.IOptions`1[Microsoft.Extensions.Logging.LoggerFactoryOptions]" }, 5, 0, 0, 6, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration"), - new ("Microsoft.Extensions.Logging", "Microsoft.Extensions.Logging.LoggerFactory", ".ctor", new[] { "System.Void", "System.Collections.Generic.IEnumerable`1[Microsoft.Extensions.Logging.ILoggerProvider]", "Microsoft.Extensions.Options.IOptionsMonitor`1[Microsoft.Extensions.Logging.LoggerFilterOptions]", "Microsoft.Extensions.Options.IOptions`1[Microsoft.Extensions.Logging.LoggerFactoryOptions]", "Microsoft.Extensions.Logging.IExternalScopeProvider" }, 7, 0, 0, 7, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration"), new ("Microsoft.Extensions.Logging", "Microsoft.Extensions.Logging.LoggerFactoryScopeProvider", "ForEachScope", new[] { "System.Void", "System.Action`2[System.Object,!!0]", "!!0" }, 2, 0, 0, 7, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerFactoryScopeProviderForEachScopeIntegration"), new ("Microsoft.Extensions.Logging.Abstractions", "Microsoft.Extensions.Logging.LoggerExternalScopeProvider", "ForEachScope", new[] { "System.Void", "System.Action`2[System.Object,!!0]", "!!0" }, 2, 0, 0, 7, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerExternalScopeProviderForEachScopeIntegration"), @@ -170,8 +167,6 @@ static InstrumentationDefinitions() new ("Confluent.Kafka", "Confluent.Kafka.Producer`2+TypedDeliveryHandlerShim_Action", ".ctor", new[] { "System.Void", "System.String", "!0", "!1", "System.Action`1[Confluent.Kafka.DeliveryReport`2[!0,!1]]" }, 1, 4, 0, 1, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Kafka.KafkaProduceSyncDeliveryHandlerIntegration"), // Log4Net - new ("log4net", "log4net.Appender.AppenderCollection", "ToArray", new[] { "log4net.Appender.IAppender[]" }, 2, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission.AppenderCollectionIntegration"), - new ("log4net", "log4net.Appender.AppenderCollection", "ToArray", new[] { "log4net.Appender.IAppender[]" }, 1, 0, 0, 1, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission.AppenderCollectionLegacyIntegration"), new ("log4net", "log4net.Util.AppenderAttachedImpl", "AppendLoopOnAppenders", new[] { "System.Int32", "log4net.Core.LoggingEvent" }, 1, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Log4Net.AppenderAttachedImplIntegration"), // MongoDb @@ -233,8 +228,6 @@ static InstrumentationDefinitions() new ("MySqlConnector", "MySqlConnector.MySqlCommand", "ExecuteScalarAsync", new[] { "System.Threading.Tasks.Task`1", "System.Threading.CancellationToken" }, 1, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.AdoNet.CommandExecuteScalarAsyncIntegration"), // NLog - new ("NLog", "NLog.LogFactory", "BuildLoggerConfiguration", new[] { "System.Void", "System.String", "NLog.Config.LoggingConfiguration" }, 5, 0, 0, 5, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.LogFactoryGetConfigurationForLoggerInstrumentation"), - new ("NLog", "NLog.LogFactory", "GetConfigurationForLogger", new[] { "System.Void", "System.String", "NLog.Config.LoggingConfiguration" }, 2, 1, 0, 4, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.LogFactoryGetConfigurationForLoggerInstrumentation"), new ("NLog", "NLog.LoggerImpl", "Write", new[] { "System.Void", "System.Type", "NLog.Internal.TargetWithFilterChain", "NLog.LogEventInfo", "NLog.LogFactory" }, 1, 0, 0, 5, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.LogsInjection.LoggerImplWriteIntegration"), // Npgsql @@ -283,7 +276,6 @@ static InstrumentationDefinitions() // Serilog new ("Serilog", "Serilog.Core.Logger", "Dispatch", new[] { "System.Void", "Serilog.Events.LogEvent" }, 2, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.LogsInjection.LoggerDispatchInstrumentation"), new ("Serilog", "Serilog.Core.Pipeline.Logger", "Dispatch", new[] { "System.Void", "Serilog.Events.LogEvent" }, 1, 4, 0, 1, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.LogsInjection.LoggerDispatchInstrumentation"), - new ("Serilog", "Serilog.LoggerConfiguration", "CreateLogger", new[] { "Serilog.Core.Logger" }, 1, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.LoggerConfigurationInstrumentation"), // ServiceStackRedis new ("ServiceStack.Redis", "ServiceStack.Redis.RedisNativeClient", "SendReceive", new[] { "T", "System.Byte[][]", "System.Func`1[!!0]", "System.Action`1[System.Func`1[!!0]]", "System.Boolean" }, 4, 0, 0, 6, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Redis.ServiceStack.RedisNativeClientSendReceiveIntegration"), @@ -537,10 +529,7 @@ private static Payload GetDerivedDefinitionsArray(InstrumentationCategory instru or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Http.HttpClient.WinHttpHandler.WinHttpHandlerIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Http.HttpClient.WinHttpHandler.WinHttpHandlerIntegration" => Datadog.Trace.Configuration.IntegrationId.HttpMessageHandler, - "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerFactoryScopeProviderForEachScopeIntegration" + "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerFactoryScopeProviderForEachScopeIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerExternalScopeProviderForEachScopeIntegration" => Datadog.Trace.Configuration.IntegrationId.ILogger, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Kafka.KafkaConsumerCloseIntegration" @@ -551,9 +540,7 @@ private static Payload GetDerivedDefinitionsArray(InstrumentationCategory instru or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Kafka.KafkaProduceAsyncIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Kafka.KafkaProduceSyncDeliveryHandlerIntegration" => Datadog.Trace.Configuration.IntegrationId.Kafka, - "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission.AppenderCollectionIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission.AppenderCollectionLegacyIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Log4Net.AppenderAttachedImplIntegration" + "Datadog.Trace.ClrProfiler.AutoInstrumentation.Log4Net.AppenderAttachedImplIntegration" => Datadog.Trace.Configuration.IntegrationId.Log4Net, "Datadog.Trace.ClrProfiler.AutoInstrumentation.MongoDb.IWireProtocol_Generic_Execute_Integration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.MongoDb.IWireProtocol_ExecuteAsync_Integration" @@ -580,9 +567,7 @@ private static Payload GetDerivedDefinitionsArray(InstrumentationCategory instru or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing.MsTestV2.UnitTestRunnerRunSingleTestIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing.MsTestV2.TestMethodAttributeExecuteIntegration" => Datadog.Trace.Configuration.IntegrationId.MsTestV2, - "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.LogFactoryGetConfigurationForLoggerInstrumentation" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.LogFactoryGetConfigurationForLoggerInstrumentation" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.LogsInjection.LoggerImplWriteIntegration" + "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.LogsInjection.LoggerImplWriteIntegration" => Datadog.Trace.Configuration.IntegrationId.NLog, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing.NUnit.NUnitTestAssemblyRunnerWaitForCompletionIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing.NUnit.NUnitSkipCommandExecuteIntegration" @@ -599,7 +584,6 @@ private static Payload GetDerivedDefinitionsArray(InstrumentationCategory instru => Datadog.Trace.Configuration.IntegrationId.RabbitMQ, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.LogsInjection.LoggerDispatchInstrumentation" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.LogsInjection.LoggerDispatchInstrumentation" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.LoggerConfigurationInstrumentation" => Datadog.Trace.Configuration.IntegrationId.Serilog, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Redis.ServiceStack.RedisNativeClientSendReceiveIntegration" => Datadog.Trace.Configuration.IntegrationId.ServiceStackRedis, diff --git a/tracer/src/Datadog.Trace/Generated/net6.0/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.InstrumentationDefinitions.InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs b/tracer/src/Datadog.Trace/Generated/net6.0/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.InstrumentationDefinitions.InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs index 78fd15ff9..a497416e2 100644 --- a/tracer/src/Datadog.Trace/Generated/net6.0/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.InstrumentationDefinitions.InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs +++ b/tracer/src/Datadog.Trace/Generated/net6.0/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.InstrumentationDefinitions.InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs @@ -151,9 +151,6 @@ static InstrumentationDefinitions() new ("System.Net.Http.WinHttpHandler", "System.Net.Http.WinHttpHandler", "SendAsync", new[] { "System.Threading.Tasks.Task`1", "System.Net.Http.HttpRequestMessage", "System.Threading.CancellationToken" }, 4, 0, 0, 7, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Http.HttpClient.WinHttpHandler.WinHttpHandlerIntegration"), // ILogger - new ("Microsoft.Extensions.Logging", "Microsoft.Extensions.Logging.LoggerFactory", ".ctor", new[] { "System.Void", "System.Collections.Generic.IEnumerable`1[Microsoft.Extensions.Logging.ILoggerProvider]", "Microsoft.Extensions.Options.IOptionsMonitor`1[Microsoft.Extensions.Logging.LoggerFilterOptions]" }, 2, 0, 0, 3, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration"), - new ("Microsoft.Extensions.Logging", "Microsoft.Extensions.Logging.LoggerFactory", ".ctor", new[] { "System.Void", "System.Collections.Generic.IEnumerable`1[Microsoft.Extensions.Logging.ILoggerProvider]", "Microsoft.Extensions.Options.IOptionsMonitor`1[Microsoft.Extensions.Logging.LoggerFilterOptions]", "Microsoft.Extensions.Options.IOptions`1[Microsoft.Extensions.Logging.LoggerFactoryOptions]" }, 5, 0, 0, 6, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration"), - new ("Microsoft.Extensions.Logging", "Microsoft.Extensions.Logging.LoggerFactory", ".ctor", new[] { "System.Void", "System.Collections.Generic.IEnumerable`1[Microsoft.Extensions.Logging.ILoggerProvider]", "Microsoft.Extensions.Options.IOptionsMonitor`1[Microsoft.Extensions.Logging.LoggerFilterOptions]", "Microsoft.Extensions.Options.IOptions`1[Microsoft.Extensions.Logging.LoggerFactoryOptions]", "Microsoft.Extensions.Logging.IExternalScopeProvider" }, 7, 0, 0, 7, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration"), new ("Microsoft.Extensions.Logging", "Microsoft.Extensions.Logging.LoggerFactoryScopeProvider", "ForEachScope", new[] { "System.Void", "System.Action`2[System.Object,!!0]", "!!0" }, 2, 0, 0, 7, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerFactoryScopeProviderForEachScopeIntegration"), new ("Microsoft.Extensions.Logging.Abstractions", "Microsoft.Extensions.Logging.LoggerExternalScopeProvider", "ForEachScope", new[] { "System.Void", "System.Action`2[System.Object,!!0]", "!!0" }, 2, 0, 0, 7, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerExternalScopeProviderForEachScopeIntegration"), @@ -167,8 +164,6 @@ static InstrumentationDefinitions() new ("Confluent.Kafka", "Confluent.Kafka.Producer`2+TypedDeliveryHandlerShim_Action", ".ctor", new[] { "System.Void", "System.String", "!0", "!1", "System.Action`1[Confluent.Kafka.DeliveryReport`2[!0,!1]]" }, 1, 4, 0, 1, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Kafka.KafkaProduceSyncDeliveryHandlerIntegration"), // Log4Net - new ("log4net", "log4net.Appender.AppenderCollection", "ToArray", new[] { "log4net.Appender.IAppender[]" }, 2, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission.AppenderCollectionIntegration"), - new ("log4net", "log4net.Appender.AppenderCollection", "ToArray", new[] { "log4net.Appender.IAppender[]" }, 1, 0, 0, 1, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission.AppenderCollectionLegacyIntegration"), new ("log4net", "log4net.Util.AppenderAttachedImpl", "AppendLoopOnAppenders", new[] { "System.Int32", "log4net.Core.LoggingEvent" }, 1, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Log4Net.AppenderAttachedImplIntegration"), // MongoDb @@ -230,8 +225,6 @@ static InstrumentationDefinitions() new ("MySqlConnector", "MySqlConnector.MySqlCommand", "ExecuteScalarAsync", new[] { "System.Threading.Tasks.Task`1", "System.Threading.CancellationToken" }, 1, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.AdoNet.CommandExecuteScalarAsyncIntegration"), // NLog - new ("NLog", "NLog.LogFactory", "BuildLoggerConfiguration", new[] { "System.Void", "System.String", "NLog.Config.LoggingConfiguration" }, 5, 0, 0, 5, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.LogFactoryGetConfigurationForLoggerInstrumentation"), - new ("NLog", "NLog.LogFactory", "GetConfigurationForLogger", new[] { "System.Void", "System.String", "NLog.Config.LoggingConfiguration" }, 2, 1, 0, 4, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.LogFactoryGetConfigurationForLoggerInstrumentation"), new ("NLog", "NLog.LoggerImpl", "Write", new[] { "System.Void", "System.Type", "NLog.Internal.TargetWithFilterChain", "NLog.LogEventInfo", "NLog.LogFactory" }, 1, 0, 0, 5, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.LogsInjection.LoggerImplWriteIntegration"), // Npgsql @@ -280,7 +273,6 @@ static InstrumentationDefinitions() // Serilog new ("Serilog", "Serilog.Core.Logger", "Dispatch", new[] { "System.Void", "Serilog.Events.LogEvent" }, 2, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.LogsInjection.LoggerDispatchInstrumentation"), new ("Serilog", "Serilog.Core.Pipeline.Logger", "Dispatch", new[] { "System.Void", "Serilog.Events.LogEvent" }, 1, 4, 0, 1, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.LogsInjection.LoggerDispatchInstrumentation"), - new ("Serilog", "Serilog.LoggerConfiguration", "CreateLogger", new[] { "Serilog.Core.Logger" }, 1, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.LoggerConfigurationInstrumentation"), // ServiceStackRedis new ("ServiceStack.Redis", "ServiceStack.Redis.RedisNativeClient", "SendReceive", new[] { "T", "System.Byte[][]", "System.Func`1[!!0]", "System.Action`1[System.Func`1[!!0]]", "System.Boolean" }, 4, 0, 0, 6, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Redis.ServiceStack.RedisNativeClientSendReceiveIntegration"), @@ -526,10 +518,7 @@ private static Payload GetDerivedDefinitionsArray(InstrumentationCategory instru or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Http.HttpClient.WinHttpHandler.WinHttpHandlerIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Http.HttpClient.WinHttpHandler.WinHttpHandlerIntegration" => Datadog.Trace.Configuration.IntegrationId.HttpMessageHandler, - "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerFactoryScopeProviderForEachScopeIntegration" + "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerFactoryScopeProviderForEachScopeIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerExternalScopeProviderForEachScopeIntegration" => Datadog.Trace.Configuration.IntegrationId.ILogger, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Kafka.KafkaConsumerCloseIntegration" @@ -540,9 +529,7 @@ private static Payload GetDerivedDefinitionsArray(InstrumentationCategory instru or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Kafka.KafkaProduceAsyncIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Kafka.KafkaProduceSyncDeliveryHandlerIntegration" => Datadog.Trace.Configuration.IntegrationId.Kafka, - "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission.AppenderCollectionIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission.AppenderCollectionLegacyIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Log4Net.AppenderAttachedImplIntegration" + "Datadog.Trace.ClrProfiler.AutoInstrumentation.Log4Net.AppenderAttachedImplIntegration" => Datadog.Trace.Configuration.IntegrationId.Log4Net, "Datadog.Trace.ClrProfiler.AutoInstrumentation.MongoDb.IWireProtocol_Generic_Execute_Integration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.MongoDb.IWireProtocol_ExecuteAsync_Integration" @@ -569,9 +556,7 @@ private static Payload GetDerivedDefinitionsArray(InstrumentationCategory instru or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing.MsTestV2.UnitTestRunnerRunSingleTestIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing.MsTestV2.TestMethodAttributeExecuteIntegration" => Datadog.Trace.Configuration.IntegrationId.MsTestV2, - "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.LogFactoryGetConfigurationForLoggerInstrumentation" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.LogFactoryGetConfigurationForLoggerInstrumentation" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.LogsInjection.LoggerImplWriteIntegration" + "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.LogsInjection.LoggerImplWriteIntegration" => Datadog.Trace.Configuration.IntegrationId.NLog, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing.NUnit.NUnitTestAssemblyRunnerWaitForCompletionIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing.NUnit.NUnitSkipCommandExecuteIntegration" @@ -588,7 +573,6 @@ private static Payload GetDerivedDefinitionsArray(InstrumentationCategory instru => Datadog.Trace.Configuration.IntegrationId.RabbitMQ, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.LogsInjection.LoggerDispatchInstrumentation" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.LogsInjection.LoggerDispatchInstrumentation" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.LoggerConfigurationInstrumentation" => Datadog.Trace.Configuration.IntegrationId.Serilog, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Redis.ServiceStack.RedisNativeClientSendReceiveIntegration" => Datadog.Trace.Configuration.IntegrationId.ServiceStackRedis, diff --git a/tracer/src/Datadog.Trace/Generated/netcoreapp3.1/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.InstrumentationDefinitions.InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs b/tracer/src/Datadog.Trace/Generated/netcoreapp3.1/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.InstrumentationDefinitions.InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs index 78fd15ff9..a497416e2 100644 --- a/tracer/src/Datadog.Trace/Generated/netcoreapp3.1/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.InstrumentationDefinitions.InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs +++ b/tracer/src/Datadog.Trace/Generated/netcoreapp3.1/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.InstrumentationDefinitions.InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs @@ -151,9 +151,6 @@ static InstrumentationDefinitions() new ("System.Net.Http.WinHttpHandler", "System.Net.Http.WinHttpHandler", "SendAsync", new[] { "System.Threading.Tasks.Task`1", "System.Net.Http.HttpRequestMessage", "System.Threading.CancellationToken" }, 4, 0, 0, 7, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Http.HttpClient.WinHttpHandler.WinHttpHandlerIntegration"), // ILogger - new ("Microsoft.Extensions.Logging", "Microsoft.Extensions.Logging.LoggerFactory", ".ctor", new[] { "System.Void", "System.Collections.Generic.IEnumerable`1[Microsoft.Extensions.Logging.ILoggerProvider]", "Microsoft.Extensions.Options.IOptionsMonitor`1[Microsoft.Extensions.Logging.LoggerFilterOptions]" }, 2, 0, 0, 3, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration"), - new ("Microsoft.Extensions.Logging", "Microsoft.Extensions.Logging.LoggerFactory", ".ctor", new[] { "System.Void", "System.Collections.Generic.IEnumerable`1[Microsoft.Extensions.Logging.ILoggerProvider]", "Microsoft.Extensions.Options.IOptionsMonitor`1[Microsoft.Extensions.Logging.LoggerFilterOptions]", "Microsoft.Extensions.Options.IOptions`1[Microsoft.Extensions.Logging.LoggerFactoryOptions]" }, 5, 0, 0, 6, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration"), - new ("Microsoft.Extensions.Logging", "Microsoft.Extensions.Logging.LoggerFactory", ".ctor", new[] { "System.Void", "System.Collections.Generic.IEnumerable`1[Microsoft.Extensions.Logging.ILoggerProvider]", "Microsoft.Extensions.Options.IOptionsMonitor`1[Microsoft.Extensions.Logging.LoggerFilterOptions]", "Microsoft.Extensions.Options.IOptions`1[Microsoft.Extensions.Logging.LoggerFactoryOptions]", "Microsoft.Extensions.Logging.IExternalScopeProvider" }, 7, 0, 0, 7, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration"), new ("Microsoft.Extensions.Logging", "Microsoft.Extensions.Logging.LoggerFactoryScopeProvider", "ForEachScope", new[] { "System.Void", "System.Action`2[System.Object,!!0]", "!!0" }, 2, 0, 0, 7, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerFactoryScopeProviderForEachScopeIntegration"), new ("Microsoft.Extensions.Logging.Abstractions", "Microsoft.Extensions.Logging.LoggerExternalScopeProvider", "ForEachScope", new[] { "System.Void", "System.Action`2[System.Object,!!0]", "!!0" }, 2, 0, 0, 7, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerExternalScopeProviderForEachScopeIntegration"), @@ -167,8 +164,6 @@ static InstrumentationDefinitions() new ("Confluent.Kafka", "Confluent.Kafka.Producer`2+TypedDeliveryHandlerShim_Action", ".ctor", new[] { "System.Void", "System.String", "!0", "!1", "System.Action`1[Confluent.Kafka.DeliveryReport`2[!0,!1]]" }, 1, 4, 0, 1, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Kafka.KafkaProduceSyncDeliveryHandlerIntegration"), // Log4Net - new ("log4net", "log4net.Appender.AppenderCollection", "ToArray", new[] { "log4net.Appender.IAppender[]" }, 2, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission.AppenderCollectionIntegration"), - new ("log4net", "log4net.Appender.AppenderCollection", "ToArray", new[] { "log4net.Appender.IAppender[]" }, 1, 0, 0, 1, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission.AppenderCollectionLegacyIntegration"), new ("log4net", "log4net.Util.AppenderAttachedImpl", "AppendLoopOnAppenders", new[] { "System.Int32", "log4net.Core.LoggingEvent" }, 1, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Log4Net.AppenderAttachedImplIntegration"), // MongoDb @@ -230,8 +225,6 @@ static InstrumentationDefinitions() new ("MySqlConnector", "MySqlConnector.MySqlCommand", "ExecuteScalarAsync", new[] { "System.Threading.Tasks.Task`1", "System.Threading.CancellationToken" }, 1, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.AdoNet.CommandExecuteScalarAsyncIntegration"), // NLog - new ("NLog", "NLog.LogFactory", "BuildLoggerConfiguration", new[] { "System.Void", "System.String", "NLog.Config.LoggingConfiguration" }, 5, 0, 0, 5, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.LogFactoryGetConfigurationForLoggerInstrumentation"), - new ("NLog", "NLog.LogFactory", "GetConfigurationForLogger", new[] { "System.Void", "System.String", "NLog.Config.LoggingConfiguration" }, 2, 1, 0, 4, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.LogFactoryGetConfigurationForLoggerInstrumentation"), new ("NLog", "NLog.LoggerImpl", "Write", new[] { "System.Void", "System.Type", "NLog.Internal.TargetWithFilterChain", "NLog.LogEventInfo", "NLog.LogFactory" }, 1, 0, 0, 5, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.LogsInjection.LoggerImplWriteIntegration"), // Npgsql @@ -280,7 +273,6 @@ static InstrumentationDefinitions() // Serilog new ("Serilog", "Serilog.Core.Logger", "Dispatch", new[] { "System.Void", "Serilog.Events.LogEvent" }, 2, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.LogsInjection.LoggerDispatchInstrumentation"), new ("Serilog", "Serilog.Core.Pipeline.Logger", "Dispatch", new[] { "System.Void", "Serilog.Events.LogEvent" }, 1, 4, 0, 1, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.LogsInjection.LoggerDispatchInstrumentation"), - new ("Serilog", "Serilog.LoggerConfiguration", "CreateLogger", new[] { "Serilog.Core.Logger" }, 1, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.LoggerConfigurationInstrumentation"), // ServiceStackRedis new ("ServiceStack.Redis", "ServiceStack.Redis.RedisNativeClient", "SendReceive", new[] { "T", "System.Byte[][]", "System.Func`1[!!0]", "System.Action`1[System.Func`1[!!0]]", "System.Boolean" }, 4, 0, 0, 6, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Redis.ServiceStack.RedisNativeClientSendReceiveIntegration"), @@ -526,10 +518,7 @@ private static Payload GetDerivedDefinitionsArray(InstrumentationCategory instru or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Http.HttpClient.WinHttpHandler.WinHttpHandlerIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Http.HttpClient.WinHttpHandler.WinHttpHandlerIntegration" => Datadog.Trace.Configuration.IntegrationId.HttpMessageHandler, - "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerFactoryScopeProviderForEachScopeIntegration" + "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerFactoryScopeProviderForEachScopeIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerExternalScopeProviderForEachScopeIntegration" => Datadog.Trace.Configuration.IntegrationId.ILogger, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Kafka.KafkaConsumerCloseIntegration" @@ -540,9 +529,7 @@ private static Payload GetDerivedDefinitionsArray(InstrumentationCategory instru or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Kafka.KafkaProduceAsyncIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Kafka.KafkaProduceSyncDeliveryHandlerIntegration" => Datadog.Trace.Configuration.IntegrationId.Kafka, - "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission.AppenderCollectionIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission.AppenderCollectionLegacyIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Log4Net.AppenderAttachedImplIntegration" + "Datadog.Trace.ClrProfiler.AutoInstrumentation.Log4Net.AppenderAttachedImplIntegration" => Datadog.Trace.Configuration.IntegrationId.Log4Net, "Datadog.Trace.ClrProfiler.AutoInstrumentation.MongoDb.IWireProtocol_Generic_Execute_Integration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.MongoDb.IWireProtocol_ExecuteAsync_Integration" @@ -569,9 +556,7 @@ private static Payload GetDerivedDefinitionsArray(InstrumentationCategory instru or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing.MsTestV2.UnitTestRunnerRunSingleTestIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing.MsTestV2.TestMethodAttributeExecuteIntegration" => Datadog.Trace.Configuration.IntegrationId.MsTestV2, - "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.LogFactoryGetConfigurationForLoggerInstrumentation" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.LogFactoryGetConfigurationForLoggerInstrumentation" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.LogsInjection.LoggerImplWriteIntegration" + "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.LogsInjection.LoggerImplWriteIntegration" => Datadog.Trace.Configuration.IntegrationId.NLog, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing.NUnit.NUnitTestAssemblyRunnerWaitForCompletionIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing.NUnit.NUnitSkipCommandExecuteIntegration" @@ -588,7 +573,6 @@ private static Payload GetDerivedDefinitionsArray(InstrumentationCategory instru => Datadog.Trace.Configuration.IntegrationId.RabbitMQ, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.LogsInjection.LoggerDispatchInstrumentation" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.LogsInjection.LoggerDispatchInstrumentation" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.LoggerConfigurationInstrumentation" => Datadog.Trace.Configuration.IntegrationId.Serilog, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Redis.ServiceStack.RedisNativeClientSendReceiveIntegration" => Datadog.Trace.Configuration.IntegrationId.ServiceStackRedis, diff --git a/tracer/src/Datadog.Trace/Generated/netstandard2.0/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.InstrumentationDefinitions.InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs b/tracer/src/Datadog.Trace/Generated/netstandard2.0/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.InstrumentationDefinitions.InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs index 78fd15ff9..a497416e2 100644 --- a/tracer/src/Datadog.Trace/Generated/netstandard2.0/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.InstrumentationDefinitions.InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs +++ b/tracer/src/Datadog.Trace/Generated/netstandard2.0/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.InstrumentationDefinitions.InstrumentationDefinitionsGenerator/InstrumentationDefinitions.g.cs @@ -151,9 +151,6 @@ static InstrumentationDefinitions() new ("System.Net.Http.WinHttpHandler", "System.Net.Http.WinHttpHandler", "SendAsync", new[] { "System.Threading.Tasks.Task`1", "System.Net.Http.HttpRequestMessage", "System.Threading.CancellationToken" }, 4, 0, 0, 7, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Http.HttpClient.WinHttpHandler.WinHttpHandlerIntegration"), // ILogger - new ("Microsoft.Extensions.Logging", "Microsoft.Extensions.Logging.LoggerFactory", ".ctor", new[] { "System.Void", "System.Collections.Generic.IEnumerable`1[Microsoft.Extensions.Logging.ILoggerProvider]", "Microsoft.Extensions.Options.IOptionsMonitor`1[Microsoft.Extensions.Logging.LoggerFilterOptions]" }, 2, 0, 0, 3, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration"), - new ("Microsoft.Extensions.Logging", "Microsoft.Extensions.Logging.LoggerFactory", ".ctor", new[] { "System.Void", "System.Collections.Generic.IEnumerable`1[Microsoft.Extensions.Logging.ILoggerProvider]", "Microsoft.Extensions.Options.IOptionsMonitor`1[Microsoft.Extensions.Logging.LoggerFilterOptions]", "Microsoft.Extensions.Options.IOptions`1[Microsoft.Extensions.Logging.LoggerFactoryOptions]" }, 5, 0, 0, 6, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration"), - new ("Microsoft.Extensions.Logging", "Microsoft.Extensions.Logging.LoggerFactory", ".ctor", new[] { "System.Void", "System.Collections.Generic.IEnumerable`1[Microsoft.Extensions.Logging.ILoggerProvider]", "Microsoft.Extensions.Options.IOptionsMonitor`1[Microsoft.Extensions.Logging.LoggerFilterOptions]", "Microsoft.Extensions.Options.IOptions`1[Microsoft.Extensions.Logging.LoggerFactoryOptions]", "Microsoft.Extensions.Logging.IExternalScopeProvider" }, 7, 0, 0, 7, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration"), new ("Microsoft.Extensions.Logging", "Microsoft.Extensions.Logging.LoggerFactoryScopeProvider", "ForEachScope", new[] { "System.Void", "System.Action`2[System.Object,!!0]", "!!0" }, 2, 0, 0, 7, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerFactoryScopeProviderForEachScopeIntegration"), new ("Microsoft.Extensions.Logging.Abstractions", "Microsoft.Extensions.Logging.LoggerExternalScopeProvider", "ForEachScope", new[] { "System.Void", "System.Action`2[System.Object,!!0]", "!!0" }, 2, 0, 0, 7, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerExternalScopeProviderForEachScopeIntegration"), @@ -167,8 +164,6 @@ static InstrumentationDefinitions() new ("Confluent.Kafka", "Confluent.Kafka.Producer`2+TypedDeliveryHandlerShim_Action", ".ctor", new[] { "System.Void", "System.String", "!0", "!1", "System.Action`1[Confluent.Kafka.DeliveryReport`2[!0,!1]]" }, 1, 4, 0, 1, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Kafka.KafkaProduceSyncDeliveryHandlerIntegration"), // Log4Net - new ("log4net", "log4net.Appender.AppenderCollection", "ToArray", new[] { "log4net.Appender.IAppender[]" }, 2, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission.AppenderCollectionIntegration"), - new ("log4net", "log4net.Appender.AppenderCollection", "ToArray", new[] { "log4net.Appender.IAppender[]" }, 1, 0, 0, 1, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission.AppenderCollectionLegacyIntegration"), new ("log4net", "log4net.Util.AppenderAttachedImpl", "AppendLoopOnAppenders", new[] { "System.Int32", "log4net.Core.LoggingEvent" }, 1, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Log4Net.AppenderAttachedImplIntegration"), // MongoDb @@ -230,8 +225,6 @@ static InstrumentationDefinitions() new ("MySqlConnector", "MySqlConnector.MySqlCommand", "ExecuteScalarAsync", new[] { "System.Threading.Tasks.Task`1", "System.Threading.CancellationToken" }, 1, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.AdoNet.CommandExecuteScalarAsyncIntegration"), // NLog - new ("NLog", "NLog.LogFactory", "BuildLoggerConfiguration", new[] { "System.Void", "System.String", "NLog.Config.LoggingConfiguration" }, 5, 0, 0, 5, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.LogFactoryGetConfigurationForLoggerInstrumentation"), - new ("NLog", "NLog.LogFactory", "GetConfigurationForLogger", new[] { "System.Void", "System.String", "NLog.Config.LoggingConfiguration" }, 2, 1, 0, 4, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.LogFactoryGetConfigurationForLoggerInstrumentation"), new ("NLog", "NLog.LoggerImpl", "Write", new[] { "System.Void", "System.Type", "NLog.Internal.TargetWithFilterChain", "NLog.LogEventInfo", "NLog.LogFactory" }, 1, 0, 0, 5, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.LogsInjection.LoggerImplWriteIntegration"), // Npgsql @@ -280,7 +273,6 @@ static InstrumentationDefinitions() // Serilog new ("Serilog", "Serilog.Core.Logger", "Dispatch", new[] { "System.Void", "Serilog.Events.LogEvent" }, 2, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.LogsInjection.LoggerDispatchInstrumentation"), new ("Serilog", "Serilog.Core.Pipeline.Logger", "Dispatch", new[] { "System.Void", "Serilog.Events.LogEvent" }, 1, 4, 0, 1, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.LogsInjection.LoggerDispatchInstrumentation"), - new ("Serilog", "Serilog.LoggerConfiguration", "CreateLogger", new[] { "Serilog.Core.Logger" }, 1, 0, 0, 2, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.LoggerConfigurationInstrumentation"), // ServiceStackRedis new ("ServiceStack.Redis", "ServiceStack.Redis.RedisNativeClient", "SendReceive", new[] { "T", "System.Byte[][]", "System.Func`1[!!0]", "System.Action`1[System.Func`1[!!0]]", "System.Boolean" }, 4, 0, 0, 6, 65535, 65535, assemblyFullName, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Redis.ServiceStack.RedisNativeClientSendReceiveIntegration"), @@ -526,10 +518,7 @@ private static Payload GetDerivedDefinitionsArray(InstrumentationCategory instru or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Http.HttpClient.WinHttpHandler.WinHttpHandlerIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Http.HttpClient.WinHttpHandler.WinHttpHandlerIntegration" => Datadog.Trace.Configuration.IntegrationId.HttpMessageHandler, - "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.LoggerFactoryConstructorIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerFactoryScopeProviderForEachScopeIntegration" + "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerFactoryScopeProviderForEachScopeIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.LoggerExternalScopeProviderForEachScopeIntegration" => Datadog.Trace.Configuration.IntegrationId.ILogger, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Kafka.KafkaConsumerCloseIntegration" @@ -540,9 +529,7 @@ private static Payload GetDerivedDefinitionsArray(InstrumentationCategory instru or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Kafka.KafkaProduceAsyncIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Kafka.KafkaProduceSyncDeliveryHandlerIntegration" => Datadog.Trace.Configuration.IntegrationId.Kafka, - "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission.AppenderCollectionIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission.AppenderCollectionLegacyIntegration" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Log4Net.AppenderAttachedImplIntegration" + "Datadog.Trace.ClrProfiler.AutoInstrumentation.Log4Net.AppenderAttachedImplIntegration" => Datadog.Trace.Configuration.IntegrationId.Log4Net, "Datadog.Trace.ClrProfiler.AutoInstrumentation.MongoDb.IWireProtocol_Generic_Execute_Integration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.MongoDb.IWireProtocol_ExecuteAsync_Integration" @@ -569,9 +556,7 @@ private static Payload GetDerivedDefinitionsArray(InstrumentationCategory instru or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing.MsTestV2.UnitTestRunnerRunSingleTestIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing.MsTestV2.TestMethodAttributeExecuteIntegration" => Datadog.Trace.Configuration.IntegrationId.MsTestV2, - "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.LogFactoryGetConfigurationForLoggerInstrumentation" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.LogFactoryGetConfigurationForLoggerInstrumentation" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.LogsInjection.LoggerImplWriteIntegration" + "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.LogsInjection.LoggerImplWriteIntegration" => Datadog.Trace.Configuration.IntegrationId.NLog, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing.NUnit.NUnitTestAssemblyRunnerWaitForCompletionIntegration" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Testing.NUnit.NUnitSkipCommandExecuteIntegration" @@ -588,7 +573,6 @@ private static Payload GetDerivedDefinitionsArray(InstrumentationCategory instru => Datadog.Trace.Configuration.IntegrationId.RabbitMQ, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.LogsInjection.LoggerDispatchInstrumentation" or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.LogsInjection.LoggerDispatchInstrumentation" - or "Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.LoggerConfigurationInstrumentation" => Datadog.Trace.Configuration.IntegrationId.Serilog, "Datadog.Trace.ClrProfiler.AutoInstrumentation.Redis.ServiceStack.RedisNativeClientSendReceiveIntegration" => Datadog.Trace.Configuration.IntegrationId.ServiceStackRedis, diff --git a/tracer/src/Datadog.Trace/HttpOverStreams/DatadogHttpClient.cs b/tracer/src/Datadog.Trace/HttpOverStreams/DatadogHttpClient.cs index aafd9d24b..455e17b5b 100644 --- a/tracer/src/Datadog.Trace/HttpOverStreams/DatadogHttpClient.cs +++ b/tracer/src/Datadog.Trace/HttpOverStreams/DatadogHttpClient.cs @@ -34,9 +34,6 @@ private DatadogHttpClient(HttpHeaderHelperBase headerHelper) public static DatadogHttpClient CreateTraceAgentClient() => new DatadogHttpClient(new TraceAgentHttpHeaderHelper()); - public static DatadogHttpClient CreateTelemetryAgentClient() - => new DatadogHttpClient(new TelemetryAgentHttpHeaderHelper()); - public async Task SendAsync(HttpRequest request, Stream requestStream, Stream responseStream) { await SendRequestAsync(request, requestStream).ConfigureAwait(false); diff --git a/tracer/src/Datadog.Trace/HttpOverStreams/TelemetryAgentHttpHeaderHelper.cs b/tracer/src/Datadog.Trace/HttpOverStreams/TelemetryAgentHttpHeaderHelper.cs deleted file mode 100644 index d6b12e23e..000000000 --- a/tracer/src/Datadog.Trace/HttpOverStreams/TelemetryAgentHttpHeaderHelper.cs +++ /dev/null @@ -1,33 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -#nullable enable - -using System.Linq; -using Datadog.Trace.Telemetry; - -namespace Datadog.Trace.HttpOverStreams -{ - internal class TelemetryAgentHttpHeaderHelper : HttpHeaderHelperBase - { - private static string? _metadataHeaders = null; - - protected override string MetadataHeaders - { - get - { - if (_metadataHeaders == null) - { - var headers = TelemetryHttpHeaderNames.GetDefaultAgentHeaders().Select(kvp => $"{kvp.Key}: {kvp.Value}{DatadogHttpValues.CrLf}"); - _metadataHeaders = string.Concat(headers); - } - - return _metadataHeaders; - } - } - - protected override string ContentType => "application/json"; - } -} diff --git a/tracer/src/Datadog.Trace/Logging/DirectSubmission/DirectLogSubmissionManager.cs b/tracer/src/Datadog.Trace/Logging/DirectSubmission/DirectLogSubmissionManager.cs index 43e76b8ec..51b579ed2 100644 --- a/tracer/src/Datadog.Trace/Logging/DirectSubmission/DirectLogSubmissionManager.cs +++ b/tracer/src/Datadog.Trace/Logging/DirectSubmission/DirectLogSubmissionManager.cs @@ -36,23 +36,7 @@ public static DirectLogSubmissionManager Create( string serviceVersion) { var formatter = new LogFormatter(settings, serviceName, env, serviceVersion); - if (previous is not null) - { - // Only the formatter uses settings that are configurable in code. - // If that ever changes, need to update the log-shipping integrations that - // currently cache the sink/settings instances - return new DirectLogSubmissionManager(previous.Settings, previous.Sink, formatter); - } - - if (!settings.IsEnabled) - { - return new DirectLogSubmissionManager(settings, new NullDatadogSink(), formatter); - } - - var apiFactory = LogsTransportStrategy.Get(settings); - var logsApi = new LogsApi(settings.ApiKey, apiFactory); - - return new DirectLogSubmissionManager(settings, new DatadogSink(logsApi, formatter, settings.BatchingOptions), formatter); + return new DirectLogSubmissionManager(settings, new NullDatadogSink(), formatter); } public async Task DisposeAsync() diff --git a/tracer/src/Datadog.Trace/Logging/DirectSubmission/DirectLogSubmissionSettings.cs b/tracer/src/Datadog.Trace/Logging/DirectSubmission/DirectLogSubmissionSettings.cs index 200e913b9..a91bb147d 100644 --- a/tracer/src/Datadog.Trace/Logging/DirectSubmission/DirectLogSubmissionSettings.cs +++ b/tracer/src/Datadog.Trace/Logging/DirectSubmission/DirectLogSubmissionSettings.cs @@ -7,11 +7,7 @@ #nullable enable -using System; -using System.Collections.Generic; -using System.Linq; using Datadog.Trace.Configuration; -using Datadog.Trace.PlatformHelpers; namespace Datadog.Trace.Logging.DirectSubmission { @@ -20,141 +16,11 @@ namespace Datadog.Trace.Logging.DirectSubmission /// internal class DirectLogSubmissionSettings { - private const string DefaultSource = "csharp"; - private const string IntakePrefix = "https://http-intake.logs."; - private const string DefaultSite = "datadoghq.com"; - private const string IntakeSuffix = ":443"; - private const DirectSubmissionLogLevel DefaultMinimumLevel = DirectSubmissionLogLevel.Information; - private const int DefaultBatchSizeLimit = 1000; - private const int DefaultQueueSizeLimit = 100_000; - private const int DefaultBatchPeriodSeconds = 2; - - public DirectLogSubmissionSettings() - : this(source: null) - { - } - public DirectLogSubmissionSettings(IConfigurationSource? source) { - DirectLogSubmissionHost = source?.GetString(ConfigurationKeys.DirectLogSubmission.Host) - ?? HostMetadata.Instance.Hostname; - DirectLogSubmissionSource = source?.GetString(ConfigurationKeys.DirectLogSubmission.Source) ?? DefaultSource; - - var overriddenSubmissionUrl = source?.GetString(ConfigurationKeys.DirectLogSubmission.Url); - if (!string.IsNullOrEmpty(overriddenSubmissionUrl)) - { - // if they provide a url, use it - DirectLogSubmissionUrl = overriddenSubmissionUrl; - } - else - { - // They didn't provide a URL, use the default (With SIGNALFX_SITE if provided) - var specificSite = source?.GetString(ConfigurationKeys.Site); - var ddSite = string.IsNullOrEmpty(specificSite) - ? DefaultSite - : specificSite; - - DirectLogSubmissionUrl = $"{IntakePrefix}{ddSite}{IntakeSuffix}"; - } - - DirectLogSubmissionMinimumLevel = DirectSubmissionLogLevelExtensions.Parse( - source?.GetString(ConfigurationKeys.DirectLogSubmission.MinimumLevel), DefaultMinimumLevel); - - var globalTags = source?.GetDictionary(ConfigurationKeys.DirectLogSubmission.GlobalTags) - ?? source?.GetDictionary(ConfigurationKeys.GlobalTags) - // backwards compatibility for names used in the past - ?? source?.GetDictionary("SIGNALFX_GLOBAL_TAGS"); - - DirectLogSubmissionGlobalTags = globalTags?.Where(kvp => !string.IsNullOrWhiteSpace(kvp.Key) && !string.IsNullOrWhiteSpace(kvp.Value)) - .ToDictionary(kvp => kvp.Key.Trim(), kvp => kvp.Value.Trim()) - ?? new Dictionary(); - - var logSubmissionIntegrations = source?.GetString(ConfigurationKeys.DirectLogSubmission.EnabledIntegrations) - ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) ?? - Enumerable.Empty(); - DirectLogSubmissionEnabledIntegrations = new HashSet(logSubmissionIntegrations, StringComparer.OrdinalIgnoreCase); - - var batchSizeLimit = source?.GetInt32(ConfigurationKeys.DirectLogSubmission.BatchSizeLimit); - DirectLogSubmissionBatchSizeLimit = batchSizeLimit is null or <= 0 - ? DefaultBatchSizeLimit - : batchSizeLimit.Value; - - var queueSizeLimit = source?.GetInt32(ConfigurationKeys.DirectLogSubmission.QueueSizeLimit); - DirectLogSubmissionQueueSizeLimit = queueSizeLimit is null or <= 0 - ? DefaultQueueSizeLimit - : queueSizeLimit.Value; - - var seconds = source?.GetInt32(ConfigurationKeys.DirectLogSubmission.BatchPeriodSeconds); - DirectLogSubmissionBatchPeriod = TimeSpan.FromSeconds( - seconds is null or <= 0 - ? DefaultBatchPeriodSeconds - : seconds.Value); - - SignalFxAccessToken = source?.GetString(ConfigurationKeys.SignalFxAccessToken); - LogsInjectionEnabled = source?.GetBool(ConfigurationKeys.LogsInjectionEnabled); } - /// - /// Gets or Sets the integrations enabled for direct log submission - /// - /// - internal HashSet DirectLogSubmissionEnabledIntegrations { get; set; } - - /// - /// Gets or Sets the originating host name for direct logs submission - /// - /// - internal string DirectLogSubmissionHost { get; set; } - - /// - /// Gets or Sets the originating source for direct logs submission - /// - /// - internal string DirectLogSubmissionSource { get; set; } - - /// - /// Gets or sets the global tags, which are applied to all directly submitted logs. If not provided, - /// are used instead - /// - /// - internal IDictionary DirectLogSubmissionGlobalTags { get; set; } - - /// - /// Gets or sets the url to send logs to - /// - /// - internal string? DirectLogSubmissionUrl { get; set; } - - /// - /// Gets or sets the minimum level logs should have to be sent to the intake. - /// - /// - internal DirectSubmissionLogLevel DirectLogSubmissionMinimumLevel { get; set; } - - /// - /// Gets or sets the maximum number of logs to send at one time - /// - /// - internal int DirectLogSubmissionBatchSizeLimit { get; set; } - - /// - /// Gets or sets the maximum number of logs to hold in internal queue at any one time - /// - /// - internal int DirectLogSubmissionQueueSizeLimit { get; set; } - - /// - /// Gets or sets the time to wait between checking for batches - /// - /// - internal TimeSpan DirectLogSubmissionBatchPeriod { get; set; } - - /// - /// Gets or sets the SignalFx Access Token - /// - internal string? SignalFxAccessToken { get; set; } - /// /// Gets or sets whether logs injection has been explicitly enabled or disabled /// diff --git a/tracer/src/Datadog.Trace/Logging/DirectSubmission/ImmutableDirectLogSubmissionSettings.cs b/tracer/src/Datadog.Trace/Logging/DirectSubmission/ImmutableDirectLogSubmissionSettings.cs index 658a85c9d..2d078358f 100644 --- a/tracer/src/Datadog.Trace/Logging/DirectSubmission/ImmutableDirectLogSubmissionSettings.cs +++ b/tracer/src/Datadog.Trace/Logging/DirectSubmission/ImmutableDirectLogSubmissionSettings.cs @@ -8,8 +8,6 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using Datadog.Trace.Configuration; using Datadog.Trace.Logging.DirectSubmission.Sink.PeriodicBatching; @@ -77,130 +75,6 @@ private ImmutableDirectLogSubmissionSettings( public BatchingSinkOptions BatchingOptions { get; } - public static ImmutableDirectLogSubmissionSettings Create(TracerSettings settings) - => Create(settings.LogSubmissionSettings); - - public static ImmutableDirectLogSubmissionSettings Create(DirectLogSubmissionSettings settings) - => Create( - host: settings.DirectLogSubmissionHost, - source: settings.DirectLogSubmissionSource, - intakeUrl: settings.DirectLogSubmissionUrl, - accessToken: settings.SignalFxAccessToken, - minimumLevel: settings.DirectLogSubmissionMinimumLevel, - globalTags: settings.DirectLogSubmissionGlobalTags, - enabledLogShippingIntegrations: settings.DirectLogSubmissionEnabledIntegrations, - batchingOptions: new BatchingSinkOptions( - batchSizeLimit: settings.DirectLogSubmissionBatchSizeLimit, - queueLimit: settings.DirectLogSubmissionQueueSizeLimit, - period: settings.DirectLogSubmissionBatchPeriod)); - - public static ImmutableDirectLogSubmissionSettings Create( - string? host, - string? source, - string? intakeUrl, - string? accessToken, - DirectSubmissionLogLevel minimumLevel, - IDictionary globalTags, - ICollection enabledLogShippingIntegrations, - BatchingSinkOptions batchingOptions) - { - if (enabledLogShippingIntegrations.Count == 0) - { - // not trying to enable log submission, so don't log any errors and create a _null_ implementation - return CreateNullSettings(); - } - - var isEnabled = true; - var validationErrors = new List(); - - if (string.IsNullOrWhiteSpace(host)) - { - isEnabled = false; - validationErrors.Add($"Missing required setting '{ConfigurationKeys.DirectLogSubmission.Host}'."); - } - - if (string.IsNullOrWhiteSpace(source)) - { - isEnabled = false; - validationErrors.Add($"Missing required setting '{ConfigurationKeys.DirectLogSubmission.Source}'."); - } - - if (!Uri.TryCreate(intakeUrl, UriKind.Absolute, out var intakeUri)) - { - isEnabled = false; - validationErrors.Add($"The intake url '{intakeUrl}' was not a valid URL."); - } - - if (string.IsNullOrWhiteSpace(accessToken)) - { - isEnabled = false; - validationErrors.Add($"Missing required settings '{ConfigurationKeys.SignalFxAccessToken}'."); - } - - var stringifiedTags = StringifyGlobalTags(globalTags); - var enabledIntegrations = new bool[ValuesRegistry.Ids.Count]; - var enabledIntegrationNames = new List(SupportedIntegrations.Length); - - foreach (var integrationName in enabledLogShippingIntegrations) - { - if (!ValuesRegistry.TryGetValue(integrationName, out var integrationId)) - { - validationErrors.Add( - "Unknown integration: " + integrationName + - ". Use a valid logs integration name: " + - string.Join(", ", SupportedIntegrations.Select(x => ValuesRegistry.GetName(x)))); - continue; - } - - if (!SupportedIntegrations.Contains(integrationId)) - { - validationErrors.Add( - "Integration: " + integrationName + " is not a supported direct log submission integration. " + - "Use one of " + string.Join(", ", SupportedIntegrations.Select(x => ValuesRegistry.GetName(x)))); - continue; - } - - if (!enabledIntegrations[(int)integrationId]) - { - enabledIntegrationNames.Add(ValuesRegistry.GetName(integrationId)); - enabledIntegrations[(int)integrationId] = true; - } - } - - return new ImmutableDirectLogSubmissionSettings( - host: host ?? string.Empty, - source: source ?? string.Empty, - globalTags: stringifiedTags, - intakeUrl: intakeUri!, - apiKey: accessToken ?? string.Empty, - isEnabled: isEnabled, - minimumLevel: minimumLevel, - enabledIntegrations: enabledIntegrations, - validationErrors, - enabledIntegrationNames, - batchingOptions); - } - - private static string StringifyGlobalTags(IDictionary globalTags) - { - if (globalTags.Count == 0) - { - return string.Empty; - } - - var sb = new StringBuilder(); - foreach (var tagPair in globalTags) - { - sb.Append(tagPair.Key) - .Append(':') - .Append(tagPair.Value) - .Append(','); - } - - // remove final joiner - return sb.ToString(startIndex: 0, length: sb.Length - 1); - } - public static ImmutableDirectLogSubmissionSettings CreateNullSettings() { var emptyList = new List(0); diff --git a/tracer/src/Datadog.Trace/Logging/DirectSubmission/LogsTransportStrategy.cs b/tracer/src/Datadog.Trace/Logging/DirectSubmission/LogsTransportStrategy.cs deleted file mode 100644 index a969b6918..000000000 --- a/tracer/src/Datadog.Trace/Logging/DirectSubmission/LogsTransportStrategy.cs +++ /dev/null @@ -1,32 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System; -using Datadog.Trace.Agent; -using Datadog.Trace.Agent.Transports; -using Datadog.Trace.Logging.DirectSubmission.Sink; - -namespace Datadog.Trace.Logging.DirectSubmission -{ - internal static class LogsTransportStrategy - { - private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(typeof(LogsTransportStrategy)); - - public static IApiRequestFactory Get(ImmutableDirectLogSubmissionSettings settings) - { - // Still quite a long time, but we could be sending a lot of data - var timeout = TimeSpan.FromSeconds(15); - -#if NETCOREAPP - Log.Information("Using {FactoryType} for log submission transport.", nameof(HttpClientRequestFactory)); - return new HttpClientRequestFactory(settings.IntakeUrl, LogsApiHeaderNames.DefaultHeaders, timeout: timeout); -#else - Log.Information("Using {FactoryType} for log submission transport.", nameof(ApiWebRequestFactory)); - return new ApiWebRequestFactory(settings.IntakeUrl, LogsApiHeaderNames.DefaultHeaders, timeout: timeout); -#endif - } - } -} diff --git a/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/DatadogSink.cs b/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/DatadogSink.cs deleted file mode 100644 index 2b93997ca..000000000 --- a/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/DatadogSink.cs +++ /dev/null @@ -1,190 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Text; -using System.Threading.Tasks; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink.PeriodicBatching; - -namespace Datadog.Trace.Logging.DirectSubmission.Sink -{ - internal class DatadogSink : BatchingSink, IDatadogSink - { - // Maximum size for a single log is 1MB, we slightly err on the cautious side - internal const int MaxMessageSizeBytes = 1000 * 1024; - - // Maximum content size per payload is 5MB compressed - // Stay conservative with max payload size of 3MB - internal const int MaxTotalSizeBytes = (3 * 1024 * 1024); - - // Initial size of the per-event string builder - // Should be big enough to handle _most_ logs to avoid too many initial resizes - internal const int InitialBuilderSizeBytes = 10 * 1024; // 10 KB - - // Initial size of the full serialized set of logs - // Should be big enough to handle _most_ cases to avoid too many resizes - internal const int InitialAllLogsSizeBytes = 100 * 1024; // 0.1 MB - - // These are specific to the JSON/HTTP formatting, so probably shouldn't be constants - // but this will do for now - private const byte PrefixAsUtf8Byte = 0x5b; // '[' - private const byte SuffixAsUtf8Byte = 0x5D; // ']' - private const byte SeparatorAsUtf8Byte = 0x2C; // ',' - - private readonly IDatadogLogger _logger = DatadogLogging.GetLoggerFor(); - private readonly ILogsApi _api; - private readonly LogFormatter _formatter; - private readonly Action? _oversizeLogCallback; - private readonly StringBuilder _logStringBuilder = new(InitialBuilderSizeBytes); - private byte[] _serializedLogs = new byte[InitialAllLogsSizeBytes]; - private int _byteCount = 0; - private int _logCount = 0; - - public DatadogSink(ILogsApi api, LogFormatter formatter, BatchingSinkOptions sinkOptions) - : this(api, formatter, sinkOptions, oversizeLogCallback: null, sinkDisabledCallback: null) - { - } - - public DatadogSink( - ILogsApi api, - LogFormatter formatter, - BatchingSinkOptions sinkOptions, - Action? oversizeLogCallback, - Action? sinkDisabledCallback) - : base(sinkOptions, sinkDisabledCallback) - { - _api = api; - _formatter = formatter; - _oversizeLogCallback = oversizeLogCallback; - } - - /// - /// Emit a batch of log events to Datadog logs-backend. - /// - /// The events to emit. - protected override async Task EmitBatch(Queue events) - { - var allSucceeded = true; - try - { - if (events.Count == 0) - { - return true; - } - - // Add to the first log - _serializedLogs[0] = PrefixAsUtf8Byte; - _logCount = 0; - _byteCount = 1; - - foreach (var log in events) - { - // reset the string builder - _logStringBuilder.Clear(); - if (_logStringBuilder.Capacity > MaxMessageSizeBytes) - { - // A rogue giant message could cause the builder to grow significantly more than MaxMessageSizeBytes - // so reset the string builder when we get very large - _logStringBuilder.Capacity = InitialBuilderSizeBytes; - } - - log.Format(_logStringBuilder, _formatter); - - // would be nice to avoid this, but can't see a way without direct UTF8 serialization (System.Text.Json) - // Currently a rogue giant message still pays the serialization cost but is then thrown away - var serializedLog = _logStringBuilder.ToString(); - - var logSize = Encoding.UTF8.GetByteCount(serializedLog); - if (logSize > MaxMessageSizeBytes) - { - // Note that the logs intake will actually accept oversized logs, and then truncate them to 1MB - // We could continue to send the log as long as the total size isn't over 5MB, but not sure if - // it's worth it or not, so excluding for now. - _logger.Error("Log dropped as too large ({Size} bytes) to send to logs intake: {Log}", logSize, serializedLog); - _oversizeLogCallback?.Invoke(log); - continue; - } - - var requiredTotalSize = _byteCount + logSize + 1; // + 1 for the separate/suffix - - if (requiredTotalSize > MaxTotalSizeBytes) - { - // send what we have, add the log to the subsequent chunk - var result = await ReplaceFinalSeparatorAndSendChunk().ConfigureAwait(false); - allSucceeded &= result; - } - else if (requiredTotalSize > _serializedLogs.Length) - { - var newSize = _serializedLogs.Length; - - // Double the size of the array until it's big enough - while (newSize < requiredTotalSize) - { - newSize *= 2; - } - - if (newSize > MaxTotalSizeBytes) - { - newSize = MaxTotalSizeBytes; - } - - var newArray = new byte[newSize]; - Array.Copy(_serializedLogs, 0, newArray, 0, _serializedLogs.Length); - _serializedLogs = newArray; - } - - // add the log to the batch - var bytesWritten = Encoding.UTF8.GetBytes(serializedLog, 0, serializedLog.Length, _serializedLogs, _byteCount); - Debug.Assert(bytesWritten == logSize, "Actual bytes written should equal the log size"); - - _byteCount += bytesWritten; - - // add the separator - _serializedLogs[_byteCount] = SeparatorAsUtf8Byte; - _byteCount++; - _logCount++; - } - - if (_logCount > 0) - { - var result = await ReplaceFinalSeparatorAndSendChunk().ConfigureAwait(false); - allSucceeded &= result; - } - - return allSucceeded; - } - catch (Exception e) - { - _logger.Error(e, "An error occured sending logs to Datadog"); - return false; - } - } - - public override async Task DisposeAsync() - { - await DisposeAsync(true).ConfigureAwait(false); - _api.Dispose(); - } - - private async Task ReplaceFinalSeparatorAndSendChunk() - { - // Too large for this batch, so replace final separator and send what we have - Debug.Assert(_byteCount > 0, "Shouldn't ever be in a situation where we have 0 bytes"); - - _serializedLogs[_byteCount - 1] = SuffixAsUtf8Byte; - var result = await _api.SendLogsAsync(new ArraySegment(_serializedLogs, 0, _byteCount), _logCount).ConfigureAwait(false); - - // reset everything and on to the next log - _logCount = 0; - // keep the initial suffix - _byteCount = 1; - return result; - } - } -} diff --git a/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/ILogsApi.cs b/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/ILogsApi.cs deleted file mode 100644 index f1ccad929..000000000 --- a/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/ILogsApi.cs +++ /dev/null @@ -1,16 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System; -using System.Threading.Tasks; - -namespace Datadog.Trace.Logging.DirectSubmission.Sink -{ - internal interface ILogsApi : IDisposable - { - Task SendLogsAsync(ArraySegment logs, int numberOfLogs); - } -} diff --git a/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/LogsApi.cs b/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/LogsApi.cs deleted file mode 100644 index 07d1e175c..000000000 --- a/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/LogsApi.cs +++ /dev/null @@ -1,163 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System; -using System.Net.Sockets; -using System.Threading.Tasks; -using Datadog.Trace.Agent; - -namespace Datadog.Trace.Logging.DirectSubmission.Sink -{ - internal class LogsApi : ILogsApi - { - internal const string LogIntakePath = "/api/v2/logs"; - internal const string IntakeHeaderNameApiKey = "DD-API-KEY"; - - private const string MimeType = "application/json"; - - private const int MaxNumberRetries = 5; - private const int InitialSleepDurationMs = 500; - - private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(); - - private readonly string _apiKey; - private readonly IApiRequestFactory _apiRequestFactory; - private readonly Uri _logsIntakeEndpoint; - - public LogsApi(string apiKey, IApiRequestFactory apiRequestFactory) - { - _apiKey = apiKey; - _apiRequestFactory = apiRequestFactory; - _logsIntakeEndpoint = _apiRequestFactory.GetEndpoint(LogIntakePath); - Log.Debug("Using logs intake endpoint {LogsIntakeEndpoint}", _logsIntakeEndpoint.ToString()); - } - - public void Dispose() - { - } - - public async Task SendLogsAsync(ArraySegment logs, int numberOfLogs) - { - var retriesRemaining = MaxNumberRetries - 1; - var nextSleepDuration = InitialSleepDurationMs; - - Log.Debug("Sending {Count} logs to the logs intake", numberOfLogs); - - while (true) - { - IApiRequest request; - - try - { - request = _apiRequestFactory.Create(_logsIntakeEndpoint); - } - catch (Exception ex) - { - Log.Error(ex, "An error occurred while generating request to send logs to the intake at {IntakeEndpoint}", _apiRequestFactory.Info(_logsIntakeEndpoint)); - return false; - } - - // Set additional headers - request.AddHeader(IntakeHeaderNameApiKey, _apiKey); - - Exception? exception = null; - var isFinalTry = retriesRemaining <= 0; - var shouldRetry = true; - - try - { - IApiResponse? response = null; - - try - { - // TODO: Metrics/Telemetry? - response = await request.PostAsync(logs, MimeType).ConfigureAwait(false); - - if (response.StatusCode is >= 200 and < 300) - { - Log.Debug("Successfully sent {Count} logs to the intake", numberOfLogs); - return true; - } - - shouldRetry = response.StatusCode switch - { - 400 => false, // Bad request (likely an issue in the payload formatting) - 401 => false, // Unauthorized (likely a missing API Key) - 403 => false, // Permission issue (likely using an invalid API Key) - 408 => true, // Request Timeout, request should be retried after some time - 413 => false, // Payload too large (batch is above 5MB uncompressed) - 429 => true, // Too Many Requests, request should be retried after some time - >= 400 and < 500 => false, // generic "client" error, don't retry - _ => true // Something else, probably server error, do retry - }; - - if (!shouldRetry || isFinalTry) - { - try - { - var responseContent = await response.ReadAsStringAsync().ConfigureAwait(false); - Log.Error("Failed to submit logs with status code {StatusCode} and message: {ResponseContent}", response.StatusCode, responseContent); - } - catch (Exception ex) - { - Log.Error(ex, "Unable to read response for failed request with status code {StatusCode}", response.StatusCode); - } - } - } - finally - { - response?.Dispose(); - } - } - catch (Exception ex) - { - exception = ex; -#if DEBUG - if (ex.InnerException is InvalidOperationException) - { - Log.Error(ex, "An error occurred while sending {Count} logs to the intake at {IntakeEndpoint}", numberOfLogs, _apiRequestFactory.Info(_logsIntakeEndpoint)); - return false; - } -#endif - } - - // Error handling block - if (!shouldRetry || isFinalTry) - { - // stop retrying - Log.Error(exception, "An error occurred while sending {Count} traces to the intake at {IntakeEndpoint}", numberOfLogs, _apiRequestFactory.Info(_logsIntakeEndpoint)); - return false; - } - - // Before retry delay - if (IsSocketException(exception)) - { - Log.Debug(exception, "Unable to communicate with the logs intake at {IntakeEndpoint}", _apiRequestFactory.Info(_logsIntakeEndpoint)); - } - - // Execute retry delay - await Task.Delay(nextSleepDuration).ConfigureAwait(false); - retriesRemaining--; - nextSleepDuration *= 2; - } - } - - private static bool IsSocketException(Exception? exception) - { - while (exception is not null) - { - if (exception is SocketException) - { - return true; - } - - exception = exception.InnerException; - } - - return false; - } - } -} diff --git a/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/LogsApiHeaderNames.cs b/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/LogsApiHeaderNames.cs deleted file mode 100644 index c5f8c915e..000000000 --- a/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/LogsApiHeaderNames.cs +++ /dev/null @@ -1,25 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System.Collections.Generic; -using Datadog.Trace.Propagation; - -#nullable enable - -namespace Datadog.Trace.Logging.DirectSubmission.Sink -{ - internal static class LogsApiHeaderNames - { - /// - /// Gets the default constant header that should be added to any request to the agent - /// - internal static KeyValuePair[] DefaultHeaders { get; } = - { - new(DDHttpHeaderNames.TracingEnabled, "false"), // don't add automatic instrumentation to requests directed to the agent - }; - } -} diff --git a/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/PeriodicBatching/BatchingSink.cs b/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/PeriodicBatching/BatchingSink.cs deleted file mode 100644 index cffd3f8c1..000000000 --- a/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/PeriodicBatching/BatchingSink.cs +++ /dev/null @@ -1,266 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Threading.Tasks; -using Datadog.Trace.Util; - -namespace Datadog.Trace.Logging.DirectSubmission.Sink.PeriodicBatching -{ - internal abstract class BatchingSink - { - internal const int FailuresBeforeCircuitBreak = 10; - - private readonly IDatadogLogger _log = DatadogLogging.GetLoggerFor(); - private readonly int _batchSizeLimit; - private readonly TimeSpan _flushPeriod; - private readonly TimeSpan _circuitBreakPeriod; - private readonly BoundedConcurrentQueue _queue; - private readonly Queue _waitingBatch = new(); - private readonly CircuitBreaker _circuitBreaker; - private readonly Task _flushTask; - private readonly Action? _disableSinkAction; - private readonly TaskCompletionSource _processExit = new(TaskCreationOptions.RunContinuationsAsynchronously); - private readonly TaskCompletionSource _tracerInitialized = new(); - private readonly ConcurrentQueue> _flushCompletionSources = new(); - private volatile bool _enqueueLogEnabled = true; - - protected BatchingSink(BatchingSinkOptions sinkOptions, Action? disableSinkAction) - { - if (sinkOptions == null) - { - ThrowHelper.ThrowArgumentNullException(nameof(sinkOptions)); - } - - if (sinkOptions.BatchSizeLimit <= 0) - { - ThrowHelper.ThrowArgumentOutOfRangeException(nameof(sinkOptions), "The batch size limit must be greater than zero."); - } - - if (sinkOptions.Period <= TimeSpan.Zero) - { - ThrowHelper.ThrowArgumentOutOfRangeException(nameof(sinkOptions), "The period must be greater than zero."); - } - - _disableSinkAction = disableSinkAction; - - _batchSizeLimit = sinkOptions.BatchSizeLimit; - _flushPeriod = sinkOptions.Period; - _circuitBreakPeriod = sinkOptions.CircuitBreakPeriod; - - _queue = new BoundedConcurrentQueue(sinkOptions.QueueLimit); - _circuitBreaker = new CircuitBreaker(FailuresBeforeCircuitBreak); - - _flushTask = Task.Run(FlushBuffersTaskLoopAsync); - _flushTask.ContinueWith( - t => - { - _log.Error(t.Exception, "Error in flush task"); - _disableSinkAction?.Invoke(); - }, - TaskContinuationOptions.OnlyOnFaulted); - } - - /// - /// Emit the provided log event to the sink. If the sink is being disposed or - /// the app domain unloaded, then the event is ignored. - /// - /// Log event to emit. - /// The event is null. - public void EnqueueLog(DatadogLogEvent logEvent) - { - if (logEvent == null) - { - ThrowHelper.ThrowArgumentNullException(nameof(logEvent)); - } - - if (_processExit.Task.IsCompleted || !_enqueueLogEnabled) - { - return; - } - - _queue.TryEnqueue(logEvent); - } - - public virtual Task DisposeAsync() - { - return DisposeAsync(finalFlush: true); - } - - protected async Task DisposeAsync(bool finalFlush) - { - _processExit.TrySetResult(finalFlush); - await _flushTask.ConfigureAwait(false); - } - - public void Start() - { - _tracerInitialized.TrySetResult(true); - } - - public Task FlushAsync() - { - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - _flushCompletionSources.Enqueue(tcs); - return tcs.Task; - } - - /// - /// Emit a batch of log events, running to completion synchronously. - /// - /// The events to emit. - /// true if the batch was emitted successfully. false if there was an error - protected abstract Task EmitBatch(Queue events); - - private async Task FlushBuffersTaskLoopAsync() - { - await Task.WhenAny(_tracerInitialized.Task, _processExit.Task).ConfigureAwait(false); - - while (!_processExit.Task.IsCompleted) - { - // Extract all the pending flush TCSs before the flush call - List>? flushSources = null; - while (_flushCompletionSources.TryDequeue(out var tcs)) - { - flushSources ??= new List>(); - flushSources.Add(tcs); - } - - // Flush - var circuitStatus = await FlushLogs().ConfigureAwait(false); - - // Set results on the pending flush TCSs - if (flushSources is not null) - { - foreach (var tcs in flushSources) - { - tcs.TrySetResult(true); - } - } - - // Handle status (Note if there's a pending flush request we skip the delay) - await HandleCircuitStatus(circuitStatus, _flushCompletionSources.Count > 0).ConfigureAwait(false); - } - - _log.Debug("Terminating Log submission loop"); - if (_processExit.Task.Result) - { - var maxShutDownDelay = Task.Delay(20_000); - var finalFlushTask = FlushLogs(); - var completed = await Task.WhenAny(finalFlushTask, maxShutDownDelay).ConfigureAwait(false); - - if (completed != finalFlushTask) - { - _log.Warning("Could not finish flushing all logs before process end"); - } - } - - // Set results on the pending flush TCSs before exiting - while (_flushCompletionSources.TryDequeue(out var tcs)) - { - tcs.TrySetResult(true); - } - } - - private async Task FlushLogs() - { - try - { - var status = CircuitStatus.Closed; - var haveMultipleBatchesToSend = false; - do - { - while (_waitingBatch.Count < _batchSizeLimit && - _queue.TryDequeue(out var next)) - { - _waitingBatch.Enqueue(next); - } - - if (_waitingBatch.Count == 0) - { - // If the first batch was full, then use that status. - // If this is the first batch in this loop, then there were no logs to send - // So can't say anything about the status of the API. - return haveMultipleBatchesToSend ? status : _circuitBreaker.MarkSkipped(); - } - - var success = await EmitBatch(_waitingBatch).ConfigureAwait(false); - if (success) - { - status = _circuitBreaker.MarkSuccess(); - haveMultipleBatchesToSend = _waitingBatch.Count >= _batchSizeLimit; - if (haveMultipleBatchesToSend) - { - _waitingBatch.Clear(); - } - } - else - { - return _circuitBreaker.MarkFailure(); - } - } - while (haveMultipleBatchesToSend); - - return status; - } - catch (Exception ex) - { - _log.Error(ex, "Exception while emitting periodic batch"); - return _circuitBreaker.MarkFailure(); - } - finally - { - _waitingBatch.Clear(); - } - } - - private Task HandleCircuitStatus(CircuitStatus status, bool noDelay = false) - { - var delayTillNextEmit = _flushPeriod; - switch (status) - { - case CircuitStatus.PermanentlyBroken: - _processExit.TrySetResult(false); - _enqueueLogEnabled = false; - _disableSinkAction?.Invoke(); - - // clear the queue - while (_queue.TryDequeue(out _)) { } - - return _processExit.Task; - - case CircuitStatus.Broken: - // circuit breaker is broken, so stop queuing more logs - // for now but don't disable log shipping entirely - _enqueueLogEnabled = false; - // Wait a while before trying again - delayTillNextEmit = _circuitBreakPeriod; - break; - - case CircuitStatus.HalfBroken: - // circuit breaker is tentatively open. Start queuing logs again - _enqueueLogEnabled = true; - break; - - case CircuitStatus.Closed: - default: - _enqueueLogEnabled = true; - break; - } - - if (noDelay) - { - return Task.CompletedTask; - } - - return Task.WhenAny( - Task.Delay(delayTillNextEmit), - _processExit.Task); - } - } -} diff --git a/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/PeriodicBatching/CircuitBreaker.cs b/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/PeriodicBatching/CircuitBreaker.cs deleted file mode 100644 index f313c97f8..000000000 --- a/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/PeriodicBatching/CircuitBreaker.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -namespace Datadog.Trace.Logging.DirectSubmission.Sink.PeriodicBatching -{ - /// - /// A simple circuit breaker for periodic batching, which, if never succeeds remains permanently broken - /// - internal class CircuitBreaker - { - private readonly int _failuresBeforeBroken; - private bool _hasEverSucceeded = false; - private int _consecutiveFailureCount = 0; - - private CircuitStatus _state = CircuitStatus.Closed; - - public CircuitBreaker(int failuresBeforeBroken) - { - _failuresBeforeBroken = failuresBeforeBroken; - } - - public CircuitStatus MarkSuccess() - { - _hasEverSucceeded = true; - _consecutiveFailureCount = 0; - - _state = _state switch - { - CircuitStatus.HalfBroken => CircuitStatus.Closed, - CircuitStatus.Broken => CircuitStatus.HalfBroken, - _ => _state - }; - - return _state; - } - - public CircuitStatus MarkFailure() - { - _consecutiveFailureCount++; - - _state = _state switch - { - CircuitStatus.HalfBroken => CircuitStatus.Broken, - _ when !_hasEverSucceeded && _consecutiveFailureCount >= _failuresBeforeBroken => CircuitStatus.PermanentlyBroken, - _ when _consecutiveFailureCount >= _failuresBeforeBroken => CircuitStatus.Broken, - _ => _state, - }; - - return _state; - } - - public CircuitStatus MarkSkipped() - { - _state = _state switch - { - // treat it as a success, so we can start testing logs - CircuitStatus.Broken => CircuitStatus.HalfBroken, - // otherwise, leave things as they are - _ => _state, - }; - return _state; - } - } -} diff --git a/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/PeriodicBatching/CircuitStatus.cs b/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/PeriodicBatching/CircuitStatus.cs deleted file mode 100644 index 7f303a9ee..000000000 --- a/tracer/src/Datadog.Trace/Logging/DirectSubmission/Sink/PeriodicBatching/CircuitStatus.cs +++ /dev/null @@ -1,16 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#nullable enable - -namespace Datadog.Trace.Logging.DirectSubmission.Sink.PeriodicBatching -{ - internal enum CircuitStatus - { - Closed, - Broken, - HalfBroken, - PermanentlyBroken, - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/Collectors/ConfigurationTelemetryCollector.cs b/tracer/src/Datadog.Trace/Telemetry/Collectors/ConfigurationTelemetryCollector.cs deleted file mode 100644 index 4b99d3e57..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/Collectors/ConfigurationTelemetryCollector.cs +++ /dev/null @@ -1,181 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System; -using System.Collections.Generic; -using System.Threading; -using Datadog.Trace.Configuration; -using Datadog.Trace.ContinuousProfiler; -using Datadog.Trace.PlatformHelpers; - -namespace Datadog.Trace.Telemetry -{ - internal class ConfigurationTelemetryCollector - { - private int _tracerInstanceCount = 0; - private int _hasChangesFlag = 0; - private volatile CurrentSettings _settings; - private volatile Profiler _profiler; - private volatile bool _isTracerInitialized = false; - private AzureAppServices _azureApServicesMetadata; - private HostTelemetryData _hostData = null; - - public void RecordTracerSettings( - ImmutableTracerSettings tracerSettings, - string defaultServiceName, - AzureAppServices appServicesMetadata) - { - // Increment number of times this has been called - var reconfigureCount = Interlocked.Increment(ref _tracerInstanceCount); - var appData = new ApplicationTelemetryData( - serviceName: defaultServiceName, - env: tracerSettings.Environment, - tracerVersion: TracerConstants.AssemblyVersion, - languageName: "dotnet", - languageVersion: FrameworkDescription.Instance.ProductVersion) - { - ServiceVersion = tracerSettings.ServiceVersion, - RuntimeName = FrameworkDescription.Instance.Name, - }; - - _settings = new CurrentSettings(tracerSettings, appData); - - // The remaining properties can't change, so only need to set them the first time - if (reconfigureCount != 1) - { - SetHasChanges(); - return; - } - - _azureApServicesMetadata = appServicesMetadata; - var host = HostMetadata.Instance; - _hostData = new HostTelemetryData - { - ContainerId = ContainerMetadata.GetContainerId(), - Os = FrameworkDescription.Instance.OSPlatform, - OsVersion = Environment.OSVersion.ToString(), - Hostname = host.Hostname, - KernelName = host.KernelName, - KernelRelease = host.KernelRelease, - KernelVersion = host.KernelVersion, - }; - - _isTracerInitialized = true; - SetHasChanges(); - } - - public void RecordProfilerSettings(Profiler profiler) - { - _profiler = profiler; - SetHasChanges(); - } - - public bool HasChanges() - { - return _isTracerInitialized && _hasChangesFlag == 1; - } - - /// - /// Get the application data. Will be null if not yet initialized. - /// - public ApplicationTelemetryData GetApplicationData() - { - var settings = _settings; - return settings?.ApplicationData; - } - - /// - /// Get the application data. Will be null if not yet initialized. - /// - public HostTelemetryData GetHostData() - { - return _hostData; - } - - /// - /// Get the latest data to send to the intake. - /// - /// Null if there are no changes, or the collector is not yet initialized - public ICollection GetConfigurationData() - { - var hasChanges = Interlocked.CompareExchange(ref _hasChangesFlag, 0, 1) == 1; - if (!_isTracerInitialized || !hasChanges) - { - return null; - } - - var settings = _settings.Settings; - - var data = new List(_azureApServicesMetadata.IsRelevant ? 21 : 17) - { - new(ConfigTelemetryData.Platform, value: FrameworkDescription.Instance.ProcessArchitecture), - new(ConfigTelemetryData.Enabled, value: settings.TraceEnabled), - new(ConfigTelemetryData.AgentUrl, value: settings.ExporterSettings.AgentUri.ToString()), - new(ConfigTelemetryData.AgentTraceTransport, value: settings.ExporterSettings.TracesTransport.ToString()), - new(ConfigTelemetryData.Debug, value: GlobalSettings.Source.DebugEnabled), -#pragma warning disable CS0618 - new(ConfigTelemetryData.AnalyticsEnabled, value: settings.AnalyticsEnabled), -#pragma warning restore CS0618 - new(ConfigTelemetryData.SampleRate, value: settings.GlobalSamplingRate), - new(ConfigTelemetryData.SamplingRules, value: settings.CustomSamplingRules), - new(ConfigTelemetryData.LogInjectionEnabled, value: settings.LogsInjectionEnabled), - new(ConfigTelemetryData.RoutetemplateResourcenamesEnabled, value: settings.RouteTemplateResourceNamesEnabled), - new(ConfigTelemetryData.RoutetemplateExpansionEnabled, value: settings.ExpandRouteTemplatesEnabled), - new(ConfigTelemetryData.PartialflushEnabled, value: settings.ExporterSettings.PartialFlushEnabled), - new(ConfigTelemetryData.PartialflushMinspans, value: settings.ExporterSettings.PartialFlushMinSpans), - new(ConfigTelemetryData.AasConfigurationError, value: _azureApServicesMetadata.IsUnsafeToTrace), - new(ConfigTelemetryData.TracerInstanceCount, value: _tracerInstanceCount), - new(ConfigTelemetryData.FullTrustAppDomain, value: AppDomain.CurrentDomain.IsFullyTrusted), - new(ConfigTelemetryData.TraceMethods, value: settings.TraceMethods), - new(ConfigTelemetryData.ActivityListenerEnabled, value: settings.IsActivityListenerEnabled), - new(ConfigTelemetryData.ProfilerLoaded, value: _profiler?.Status.IsProfilerReady), - new(ConfigTelemetryData.CodeHotspotsEnabled, value: _profiler?.ContextTracker.IsEnabled), - }; - - if (_azureApServicesMetadata.IsRelevant) - { - data.Add(new(name: ConfigTelemetryData.CloudHosting, "Azure")); - data.Add(new(name: ConfigTelemetryData.AasSiteExtensionVersion, _azureApServicesMetadata.SiteExtensionVersion)); - data.Add(new(name: ConfigTelemetryData.AasAppType, _azureApServicesMetadata.SiteType)); - data.Add(new(name: ConfigTelemetryData.AasFunctionsRuntimeVersion, _azureApServicesMetadata.FunctionsExtensionVersion)); - } - - // data.Configuration["agent_reachable"] = agentError == null; - // data.Configuration["agent_error"] = agentError ?? string.Empty; - - // Global tags? - // Agent reachable - // Agent error - // Is CallTarget - // Is Docker - // Is Fargate etc - - // additional values - // Native metrics - - return data; - } - - private void SetHasChanges() - { - Interlocked.Exchange(ref _hasChangesFlag, 1); - } - - private class CurrentSettings - { - public CurrentSettings(ImmutableTracerSettings settings, ApplicationTelemetryData applicationData) - { - Settings = settings; - ApplicationData = applicationData; - } - - public ImmutableTracerSettings Settings { get; } - - public ApplicationTelemetryData ApplicationData { get; } - } - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/Collectors/DependencyTelemetryCollector.cs b/tracer/src/Datadog.Trace/Telemetry/Collectors/DependencyTelemetryCollector.cs deleted file mode 100644 index 546d270cf..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/Collectors/DependencyTelemetryCollector.cs +++ /dev/null @@ -1,114 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Reflection; -using System.Threading; - -namespace Datadog.Trace.Telemetry -{ - internal class DependencyTelemetryCollector - { - private readonly ConcurrentDictionary _assemblies = new(); - - private int _hasChangesFlag = 0; - - /// - /// Called when an assembly is loaded - /// - public void AssemblyLoaded(Assembly assembly) - { - if (!assembly.IsDynamic) - { - AssemblyLoaded(assembly.GetName()); - } - } - - // Internal for testing - internal void AssemblyLoaded(AssemblyName assembly) - { - // exclude dlls we're not interested in which have a "random" component - // ASP.NET sites generate an App_Web_*.dll with a random string for - var assemblyName = assembly.Name; - if (assemblyName is null or "" - || IsTempPathPattern(assemblyName) - || (assemblyName[0] == 'A' - && (assemblyName.StartsWith("App_Web_", StringComparison.Ordinal) - || assemblyName.StartsWith("App_Theme_", StringComparison.Ordinal) - || assemblyName.StartsWith("App_GlobalResources.", StringComparison.Ordinal) - || assemblyName.StartsWith("App_global.asax.", StringComparison.Ordinal) - || assemblyName.StartsWith("App_Code.", StringComparison.Ordinal) - || assemblyName.StartsWith("App_WebReferences.", StringComparison.Ordinal))) - || (assemblyName.Length == 36 - && assemblyName[8] == '-' - && assemblyName[13] == '-' - && assemblyName[18] == '-' - && assemblyName[23] == '-')) - { - return; - } - - var key = new DependencyTelemetryData(name: assemblyName) { Version = assembly.Version?.ToString() }; - if (_assemblies.TryAdd(key, true)) - { - SetHasChanges(); - } - } - - public bool HasChanges() - { - return _hasChangesFlag == 1; - } - - /// - /// Get the latest data to send to the intake. - /// - /// Null if there are no changes, or the collector is not yet initialized - public ICollection GetData() - { - var hasChanges = Interlocked.CompareExchange(ref _hasChangesFlag, 0, 1) == 1; - if (!hasChanges) - { - return null; - } - - return _assemblies.Keys; - } - - private static bool IsTempPathPattern(string assemblyName) - { - return assemblyName.Length == 12 // (8 + 1 + 3) - && assemblyName[8] == '.' - && IsBase32Char(assemblyName[0]) - && IsBase32Char(assemblyName[1]) - && IsBase32Char(assemblyName[2]) - && IsBase32Char(assemblyName[3]) - && IsBase32Char(assemblyName[4]) - && IsBase32Char(assemblyName[5]) - && IsBase32Char(assemblyName[6]) - && IsBase32Char(assemblyName[7]) - && IsBase32Char(assemblyName[9]) - && IsBase32Char(assemblyName[10]) - && IsBase32Char(assemblyName[11]); - - static bool IsBase32Char(char c) - { - return c switch - { - >= 'a' and <= 'z' => true, - >= '0' and <= '5' => true, - _ => false - }; - } - } - - private void SetHasChanges() - { - Interlocked.Exchange(ref _hasChangesFlag, 1); - } - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/Collectors/IntegrationTelemetryCollector.cs b/tracer/src/Datadog.Trace/Telemetry/Collectors/IntegrationTelemetryCollector.cs deleted file mode 100644 index 66c5765bd..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/Collectors/IntegrationTelemetryCollector.cs +++ /dev/null @@ -1,164 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using Datadog.Trace.Configuration; - -namespace Datadog.Trace.Telemetry -{ - internal class IntegrationTelemetryCollector - { - private readonly IntegrationDetail[] _integrationsById; - - private int _hasChangesFlag = 0; - - public IntegrationTelemetryCollector() - { - _integrationsById = new IntegrationDetail[ValuesRegistry.Names.Length]; - - for (var i = 0; i < ValuesRegistry.Names.Length; i++) - { - _integrationsById[i] = new IntegrationDetail { Name = ValuesRegistry.Names[i] }; - } - } - - public void RecordTracerSettings(ImmutableTracerSettings settings) - { - for (var i = 0; i < settings.Integrations.Settings.Length; i++) - { - var integration = settings.Integrations.Settings[i]; - if (integration.Enabled == false) - { - _integrationsById[i].WasExplicitlyDisabled = 1; - } - } - - SetHasChanges(); - } - - /// - /// Should be called when an integration is first executed (not necessarily successfully) - /// - public void IntegrationRunning(IntegrationId integrationId) - { - ref var value = ref _integrationsById[(int)integrationId]; - if (value.WasExecuted == 1) - { - return; - } - - var previousValue = Interlocked.Exchange(ref value.WasExecuted, 1); - if (previousValue == 0) - { - SetHasChanges(); - } - } - - /// - /// Should be called when an integration successfully generates a span - /// - public void IntegrationGeneratedSpan(IntegrationId integrationId) - { - ref var value = ref _integrationsById[(int)integrationId]; - if (value.WasExecuted == 1 && value.HasGeneratedSpan == 1) - { - return; - } - - var previousWasExecuted = Interlocked.Exchange(ref value.WasExecuted, 1); - var previousHasGeneratedSpan = Interlocked.Exchange(ref value.HasGeneratedSpan, 1); - - if (previousWasExecuted == 0 || previousHasGeneratedSpan == 0) - { - SetHasChanges(); - } - } - - public void IntegrationDisabledDueToError(IntegrationId integrationId, string error) - { - ref var value = ref _integrationsById[(int)integrationId]; - if (value.Error is not null) - { - return; - } - - var previousValue = Interlocked.Exchange(ref value.Error, error); - if (previousValue is null) - { - SetHasChanges(); - } - } - - public bool HasChanges() - { - return _hasChangesFlag == 1; - } - - /// - /// Get the latest data to send to the intake. - /// - /// Null if there are no changes, or the collector is not yet initialized - public ICollection GetData() - { - var hasChanges = Interlocked.CompareExchange(ref _hasChangesFlag, 0, 1) == 1; - if (!hasChanges) - { - return null; - } - - return _integrationsById - .Select( - integration => new IntegrationTelemetryData( - name: integration.Name, - enabled: integration.HasGeneratedSpan > 0 && integration.WasExplicitlyDisabled == 0) - { - AutoEnabled = integration.WasExecuted > 0, - Error = integration.Error - }) - .ToList(); - } - - private void SetHasChanges() - { - Interlocked.Exchange(ref _hasChangesFlag, 1); - } - - internal struct IntegrationDetail - { - /// - /// Gets or sets the integration info of the integration - /// - public string Name; - - /// - /// Gets or sets a value indicating whether an integration successfully generated a span - /// 0 = not generated, 1 = generated - /// - public int HasGeneratedSpan; - - /// - /// Gets or sets a value indicating whether the integration ever executed - /// 0 = not generated, 1 = generated - /// - public int WasExecuted; - - /// - /// Gets or sets a value indicating whether the integration was disabled by a user - /// 0 = not generated, 1 = generated - /// - public int WasExplicitlyDisabled; - - /// - /// Gets or sets a value indicating whether an integration was disabled due to a fatal error - /// - public string Error; - } - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/DTOs/AppDependenciesLoadedPayload.cs b/tracer/src/Datadog.Trace/Telemetry/DTOs/AppDependenciesLoadedPayload.cs deleted file mode 100644 index d8feaceff..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/DTOs/AppDependenciesLoadedPayload.cs +++ /dev/null @@ -1,21 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -#nullable enable - -using System.Collections.Generic; - -namespace Datadog.Trace.Telemetry -{ - internal class AppDependenciesLoadedPayload : IPayload - { - public AppDependenciesLoadedPayload(ICollection dependencies) - { - Dependencies = dependencies; - } - - public ICollection Dependencies { get; set; } - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/DTOs/AppIntegrationsChangedPayload.cs b/tracer/src/Datadog.Trace/Telemetry/DTOs/AppIntegrationsChangedPayload.cs deleted file mode 100644 index e1792829c..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/DTOs/AppIntegrationsChangedPayload.cs +++ /dev/null @@ -1,21 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -#nullable enable - -using System.Collections.Generic; - -namespace Datadog.Trace.Telemetry -{ - internal class AppIntegrationsChangedPayload : IPayload - { - public AppIntegrationsChangedPayload(ICollection integrations) - { - Integrations = integrations; - } - - public ICollection Integrations { get; set; } - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/DTOs/AppStartedPayload.cs b/tracer/src/Datadog.Trace/Telemetry/DTOs/AppStartedPayload.cs deleted file mode 100644 index ca06627ab..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/DTOs/AppStartedPayload.cs +++ /dev/null @@ -1,32 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -#nullable enable - -using System.Collections.Generic; - -namespace Datadog.Trace.Telemetry -{ - internal class AppStartedPayload : IPayload - { - public AppStartedPayload( - ICollection? integrations, - ICollection? dependencies, - ICollection configuration) - { - Integrations = integrations; - Dependencies = dependencies; - Configuration = configuration; - } - - public ICollection? Integrations { get; set; } - - public ICollection? Dependencies { get; set; } - - public ICollection? Configuration { get; set; } - - public ICollection? AdditionalPayload { get; set; } - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/DTOs/ApplicationTelemetryData.cs b/tracer/src/Datadog.Trace/Telemetry/DTOs/ApplicationTelemetryData.cs deleted file mode 100644 index 2f52953b6..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/DTOs/ApplicationTelemetryData.cs +++ /dev/null @@ -1,39 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -#nullable enable - -namespace Datadog.Trace.Telemetry -{ - internal class ApplicationTelemetryData - { - public ApplicationTelemetryData(string serviceName, string env, string tracerVersion, string languageName, string languageVersion) - { - ServiceName = serviceName; - Env = env; - TracerVersion = tracerVersion; - LanguageName = languageName; - LanguageVersion = languageVersion; - } - - public string ServiceName { get; set; } - - public string Env { get; set; } - - public string? ServiceVersion { get; set; } - - public string TracerVersion { get; set; } - - public string LanguageName { get; set; } - - public string LanguageVersion { get; set; } - - public string? RuntimeName { get; set; } - - public string? RuntimeVersion { get; set; } - - public string? RuntimePatches { get; set; } - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/DTOs/ConfigTelemetryData.cs b/tracer/src/Datadog.Trace/Telemetry/DTOs/ConfigTelemetryData.cs deleted file mode 100644 index 9cb9849b8..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/DTOs/ConfigTelemetryData.cs +++ /dev/null @@ -1,42 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -#nullable enable - -namespace Datadog.Trace.Telemetry -{ - internal static class ConfigTelemetryData - { - public const string Platform = "platform"; - public const string Enabled = "enabled"; - public const string AgentUrl = "agent_url"; - public const string AgentTraceTransport = "agent_transport"; - public const string Debug = "debug"; - public const string AnalyticsEnabled = "analytics_enabled"; - public const string SampleRate = "sample_rate"; - public const string SamplingRules = "sampling_rules"; - public const string LogInjectionEnabled = "logInjection_enabled"; - public const string RuntimeMetricsEnabled = "runtimemetrics_enabled"; - public const string RoutetemplateResourcenamesEnabled = "routetemplate_resourcenames_enabled"; - public const string RoutetemplateExpansionEnabled = "routetemplate_expansion_enabled"; - public const string PartialflushEnabled = "partialflush_enabled"; - public const string PartialflushMinspans = "partialflush_minspans"; - public const string TracerInstanceCount = "tracer_instance_count"; - public const string AasConfigurationError = "aas_configuration_error"; - public const string SecurityEnabled = "security_enabled"; - public const string FullTrustAppDomain = "environment_fulltrust_appdomain"; - public const string TraceMethods = "trace_methods"; - - public const string CloudHosting = "cloud_hosting"; - public const string AasSiteExtensionVersion = "aas_siteextensions_version"; - public const string AasAppType = "aas_app_type"; - public const string AasFunctionsRuntimeVersion = "aas_functions_runtime_version"; - - public const string ActivityListenerEnabled = "activity_listener_enabled"; - - public const string ProfilerLoaded = "profiler_loaded"; - public const string CodeHotspotsEnabled = "code_hotspots_enabled"; - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/DTOs/DependencyTelemetryData.cs b/tracer/src/Datadog.Trace/Telemetry/DTOs/DependencyTelemetryData.cs deleted file mode 100644 index 6350528cb..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/DTOs/DependencyTelemetryData.cs +++ /dev/null @@ -1,23 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -#nullable enable -namespace Datadog.Trace.Telemetry -{ - /// - /// Using a record as used as dictionary key so getting equality comparison for free - /// - internal record DependencyTelemetryData - { - public DependencyTelemetryData(string name) - { - Name = name; - } - - public string Name { get; set; } - - public string? Version { get; set; } - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/DTOs/GenerateMetricsPayload.cs b/tracer/src/Datadog.Trace/Telemetry/DTOs/GenerateMetricsPayload.cs deleted file mode 100644 index a44f62088..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/DTOs/GenerateMetricsPayload.cs +++ /dev/null @@ -1,14 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -namespace Datadog.Trace.Telemetry -{ - internal class GenerateMetricsPayload : IPayload - { - // TODO - // Tracer instance count - // initialization times etc - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/DTOs/HostTelemetryData.cs b/tracer/src/Datadog.Trace/Telemetry/DTOs/HostTelemetryData.cs deleted file mode 100644 index c01ee7516..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/DTOs/HostTelemetryData.cs +++ /dev/null @@ -1,26 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -#nullable enable - -namespace Datadog.Trace.Telemetry -{ - internal class HostTelemetryData - { - public string? ContainerId { get; set; } - - public string? Hostname { get; set; } - - public string? Os { get; set; } - - public string? OsVersion { get; set; } - - public string? KernelName { get; set; } - - public string? KernelRelease { get; set; } - - public string? KernelVersion { get; set; } - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/DTOs/IPayload.cs b/tracer/src/Datadog.Trace/Telemetry/DTOs/IPayload.cs deleted file mode 100644 index 2e90e92f8..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/DTOs/IPayload.cs +++ /dev/null @@ -1,11 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -namespace Datadog.Trace.Telemetry -{ - internal interface IPayload - { - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/DTOs/IntegrationTelemetryData.cs b/tracer/src/Datadog.Trace/Telemetry/DTOs/IntegrationTelemetryData.cs deleted file mode 100644 index 62cc23fb7..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/DTOs/IntegrationTelemetryData.cs +++ /dev/null @@ -1,28 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -#nullable enable - -namespace Datadog.Trace.Telemetry -{ - internal class IntegrationTelemetryData - { - public IntegrationTelemetryData(string name, bool enabled) - { - Name = name; - Enabled = enabled; - } - - public string Name { get; set; } - - public bool Enabled { get; set; } - - public bool? AutoEnabled { get; set; } - - public bool? Compatible { get; set; } - - public string? Error { get; set; } - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/DTOs/TelemetryData.cs b/tracer/src/Datadog.Trace/Telemetry/DTOs/TelemetryData.cs deleted file mode 100644 index d8e1e18f9..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/DTOs/TelemetryData.cs +++ /dev/null @@ -1,59 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -#nullable enable - -namespace Datadog.Trace.Telemetry -{ - /// - /// DTO that is serialized. - /// Be aware that the property names control serialization - /// - internal class TelemetryData - { - public TelemetryData( - string requestType, - long tracerTime, - string runtimeId, - int seqId, - ApplicationTelemetryData application, - HostTelemetryData host, - IPayload? payload) - { - RequestType = requestType; - TracerTime = tracerTime; - RuntimeId = runtimeId; - SeqId = seqId; - Application = application; - Host = host; - Payload = payload; - } - - public string ApiVersion => TelemetryConstants.ApiVersion; - - /// - /// Gets or sets requested API function - /// - public string RequestType { get; set; } - - /// - /// Gets or sets unix timestamp (in seconds) of when the message is being sent - /// - public long TracerTime { get; set; } - - public string RuntimeId { get; set; } - - /// - /// Gets or sets counter that should be auto incremented every time an API call is being made - /// - public int SeqId { get; set; } - - public ApplicationTelemetryData Application { get; set; } - - public HostTelemetryData Host { get; set; } - - public IPayload? Payload { get; set; } - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/DTOs/TelemetryValue.cs b/tracer/src/Datadog.Trace/Telemetry/DTOs/TelemetryValue.cs deleted file mode 100644 index 0e46191ab..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/DTOs/TelemetryValue.cs +++ /dev/null @@ -1,21 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -#nullable enable -namespace Datadog.Trace.Telemetry -{ - internal readonly struct TelemetryValue - { - public TelemetryValue(string name, object? value) - { - Name = name; - Value = value; - } - - public string Name { get; } - - public object? Value { get; } - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/ITelemetryTransport.cs b/tracer/src/Datadog.Trace/Telemetry/ITelemetryTransport.cs deleted file mode 100644 index 9c84a04ba..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/ITelemetryTransport.cs +++ /dev/null @@ -1,20 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Threading.Tasks; - -namespace Datadog.Trace.Telemetry -{ - internal interface ITelemetryTransport - { - /// - /// Push telemetry data to the endpoint. - /// - /// The data to send - /// true if the data was sent successfully, or a non-fatal error occurred - /// false if a fatal error occured, and no further telemetry should be sent. - Task PushTelemetry(TelemetryData data); - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/TelemetryCircuitBreaker.cs b/tracer/src/Datadog.Trace/Telemetry/TelemetryCircuitBreaker.cs deleted file mode 100644 index fce6b5616..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/TelemetryCircuitBreaker.cs +++ /dev/null @@ -1,72 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Collections.Generic; - -namespace Datadog.Trace.Telemetry -{ - internal class TelemetryCircuitBreaker - { - internal const int MaxFatalErrors = 2; - internal const int MaxTransientErrors = 5; - - private bool _hasSentSuccessfully = false; - private int _initialFatalCount = 0; - private int _failureCount = 0; - - public ICollection PreviousConfiguration { get; private set; } - - public ICollection PreviousDependencies { get; private set; } - - public ICollection PreviousIntegrations { get; private set; } - - public TelemetryPushResult Evaluate( - TelemetryPushResult result, - ICollection config, - ICollection dependencies, - ICollection integrations) - { - if (result == TelemetryPushResult.Success) - { - _hasSentSuccessfully = true; - _failureCount = 0; - PreviousConfiguration = null; - PreviousDependencies = null; - PreviousIntegrations = null; - return result; - } - else if (result == TelemetryPushResult.FatalError && !_hasSentSuccessfully) - { - _initialFatalCount++; - if (_initialFatalCount >= MaxFatalErrors) - { - // we've had MaxFatalErrors 404s, 1 minute apart, prob never going to work. - PreviousConfiguration = null; - PreviousDependencies = null; - PreviousIntegrations = null; - return TelemetryPushResult.FatalError; - } - } - else - { - _failureCount++; - if (_failureCount >= MaxTransientErrors) - { - // we've had MaxTransientErrors in a row, 1 minute apart, probably something bigger wrong - PreviousConfiguration = null; - PreviousDependencies = null; - PreviousIntegrations = null; - return TelemetryPushResult.FatalError; - } - } - - // We should retry next time - PreviousConfiguration = config; - PreviousDependencies = dependencies; - PreviousIntegrations = integrations; - return TelemetryPushResult.TransientFailure; - } - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/TelemetryConstants.cs b/tracer/src/Datadog.Trace/Telemetry/TelemetryConstants.cs deleted file mode 100644 index 940ec4084..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/TelemetryConstants.cs +++ /dev/null @@ -1,23 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; - -namespace Datadog.Trace.Telemetry -{ - internal class TelemetryConstants - { - public const string ApiVersion = "v1"; - public const string TelemetryPath = "api/v2/apmtelemetry"; - public const string TelemetryIntakePrefix = "https://instrumentation-telemetry-intake"; - public const string AgentTelemetryEndpoint = "telemetry/proxy/"; - - public const string ApiKeyHeader = "DD-API-KEY"; - public const string ApiVersionHeader = "DD-Telemetry-API-Version"; - public const string RequestTypeHeader = "DD-Telemetry-Request-Type"; - - public static readonly TimeSpan RefreshInterval = TimeSpan.FromMinutes(1); - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/TelemetryController.cs b/tracer/src/Datadog.Trace/Telemetry/TelemetryController.cs deleted file mode 100644 index 4545ef3c7..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/TelemetryController.cs +++ /dev/null @@ -1,237 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System; -using System.Reflection; -using System.Threading.Tasks; -using Datadog.Trace.Configuration; -using Datadog.Trace.ContinuousProfiler; -using Datadog.Trace.Logging; -using Datadog.Trace.PlatformHelpers; - -namespace Datadog.Trace.Telemetry -{ - internal class TelemetryController : ITelemetryController - { - private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(); - private readonly ConfigurationTelemetryCollector _configuration; - private readonly DependencyTelemetryCollector _dependencies; - private readonly IntegrationTelemetryCollector _integrations; - private readonly TelemetryDataBuilder _dataBuilder = new(); - private readonly ITelemetryTransport _transport; - private readonly TimeSpan _sendFrequency; - private readonly TaskCompletionSource _tracerInitialized = new(); - private readonly TaskCompletionSource _processExit = new(); - private readonly Task _telemetryTask; - private readonly TelemetryCircuitBreaker _circuitBreaker = new(); - - internal TelemetryController( - ConfigurationTelemetryCollector configuration, - DependencyTelemetryCollector dependencies, - IntegrationTelemetryCollector integrations, - ITelemetryTransport transport, - TimeSpan sendFrequency) - { - _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); - _dependencies = dependencies ?? throw new ArgumentNullException(nameof(dependencies)); - _integrations = integrations ?? throw new ArgumentNullException(nameof(integrations)); - _sendFrequency = sendFrequency; - _transport = transport ?? throw new ArgumentNullException(nameof(transport)); - - try - { - // Registering for the AppDomain.AssemblyLoad event cannot be called by a security transparent method - // This will only happen if the Tracer is not run full-trust - AppDomain.CurrentDomain.AssemblyLoad += CurrentDomain_OnAssemblyLoad; - var assembliesLoaded = AppDomain.CurrentDomain.GetAssemblies(); - - foreach (var t in assembliesLoaded) - { - RecordAssembly(t); - } - } - catch (Exception ex) - { - Log.Warning(ex, "Unable to register a callback to the AppDomain.AssemblyLoad event. Telemetry collection of loaded assemblies will be disabled."); - } - - _telemetryTask = Task.Run(PushTelemetryLoopAsync); - } - - public bool FatalError { get; private set; } - - public void RecordTracerSettings(ImmutableTracerSettings settings, string defaultServiceName, AzureAppServices appServicesMetadata) - { - _configuration.RecordTracerSettings(settings, defaultServiceName, appServicesMetadata); - _integrations.RecordTracerSettings(settings); - } - - public void Start() - { - _tracerInitialized.TrySetResult(true); - } - - public void RecordProfilerSettings(Profiler profiler) - => _configuration.RecordProfilerSettings(profiler); - - public void IntegrationRunning(IntegrationId integrationId) - => _integrations.IntegrationRunning(integrationId); - - public void IntegrationGeneratedSpan(IntegrationId integrationId) - => _integrations.IntegrationGeneratedSpan(integrationId); - - public void IntegrationDisabledDueToError(IntegrationId integrationId, string error) - => _integrations.IntegrationDisabledDueToError(integrationId, error); - - public async Task DisposeAsync(bool sendAppClosingTelemetry) - { - TerminateLoop(sendAppClosingTelemetry); - await _telemetryTask.ConfigureAwait(false); - } - - public Task DisposeAsync() - { - return DisposeAsync(sendAppClosingTelemetry: true); - } - - private void TerminateLoop(bool sendAppClosingTelemetry) - { - // If there's a fatal error, TerminateLoop() may be called more than once - // (at error-time, and at process end). The following are idempotent so that's safe. - _processExit.TrySetResult(sendAppClosingTelemetry); - _tracerInitialized.TrySetResult(true); - AppDomain.CurrentDomain.AssemblyLoad -= CurrentDomain_OnAssemblyLoad; - } - - private void CurrentDomain_OnAssemblyLoad(object sender, AssemblyLoadEventArgs e) - { - RecordAssembly(e.LoadedAssembly); - } - - private void RecordAssembly(Assembly assembly) - { - try - { - _dependencies.AssemblyLoaded(assembly); - } - catch (Exception ex) - { - Log.Warning(ex, "Error recording loaded assembly"); - } - } - - private async Task PushTelemetryLoopAsync() - { -#if !NET5_0_OR_GREATER - var tasks = new Task[2]; - tasks[0] = _tracerInitialized.Task; - tasks[1] = _processExit.Task; - - // wait for initialization before trying to send first telemetry - // .NET 5.0 has an explicit overload for this - await Task.WhenAny(tasks).ConfigureAwait(false); -#else - await Task.WhenAny(_tracerInitialized.Task, _processExit.Task).ConfigureAwait(false); -#endif - - while (true) - { - if (_processExit.Task.IsCompleted) - { - Log.Debug("Process exit requested, ending telemetry loop"); - var sendAppClosingTelemetry = _processExit.Task.Result; - if (sendAppClosingTelemetry) - { - await PushTelemetry(isFinalPush: true).ConfigureAwait(false); - } - - return; - } - - await PushTelemetry(isFinalPush: false).ConfigureAwait(false); - -#if NET5_0_OR_GREATER - // .NET 5.0 has an explicit overload for this - await Task.WhenAny(Task.Delay(_sendFrequency), _processExit.Task).ConfigureAwait(false); -#else - tasks[0] = Task.Delay(_sendFrequency); - await Task.WhenAny(tasks).ConfigureAwait(false); -#endif - } - } - - private async Task PushTelemetry(bool isFinalPush) - { - try - { - var application = _configuration.GetApplicationData(); - var host = _configuration.GetHostData(); - if (application is null || host is null) - { - Log.Debug("Telemetry not initialized, skipping"); - return; - } - - // These calls change the state of the collectors, so must use the data - var success = await PushTelemetry(application, host, sendHeartbeat: !isFinalPush).ConfigureAwait(false); - if (!success) - { - if (isFinalPush) - { - Log.Debug("Unable to send final telemetry, skipping app-closing telemetry "); - return; - } - else - { - FatalError = true; - Log.Debug("Unable to send telemetry, ending telemetry loop"); - TerminateLoop(sendAppClosingTelemetry: false); - } - } - - if (isFinalPush) - { - var closingTelemetryData = _dataBuilder.BuildAppClosingTelemetryData(application, host); - - Log.Debug("Pushing app-closing telemetry"); - await _transport.PushTelemetry(closingTelemetryData).ConfigureAwait(false); - } - } - catch (Exception ex) - { - Log.Warning(ex, "Error pushing telemetry"); - } - } - - private async Task PushTelemetry(ApplicationTelemetryData application, HostTelemetryData host, bool sendHeartbeat) - { - // use values from previous failed attempt if necessary - var configuration = _configuration.GetConfigurationData() ?? _circuitBreaker.PreviousConfiguration; - var dependencies = _dependencies.GetData() ?? _circuitBreaker.PreviousDependencies; - var integrations = _integrations.GetData() ?? _circuitBreaker.PreviousIntegrations; - - var data = _dataBuilder.BuildTelemetryData(application, host, configuration, dependencies, integrations, sendHeartbeat); - if (data.Length == 0) - { - return true; - } - - Log.Debug("Pushing telemetry changes"); - foreach (var telemetryData in data) - { - var result = await _transport.PushTelemetry(telemetryData).ConfigureAwait(false); - if (_circuitBreaker.Evaluate(result, configuration, dependencies, integrations) == TelemetryPushResult.FatalError) - { - // big problem, abandon hope - return false; - } - } - - return true; - } - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/TelemetryDataBuilder.cs b/tracer/src/Datadog.Trace/Telemetry/TelemetryDataBuilder.cs deleted file mode 100644 index 7c81e6fc1..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/TelemetryDataBuilder.cs +++ /dev/null @@ -1,126 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -#nullable enable - -using System; -using System.Collections.Generic; -using System.Threading; -using Datadog.Trace.ClrProfiler; -using Datadog.Trace.Logging; -using Datadog.Trace.Util; - -namespace Datadog.Trace.Telemetry -{ - internal class TelemetryDataBuilder - { - private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(); - private int _sequence = 0; - - public TelemetryData[] BuildTelemetryData( - ApplicationTelemetryData? application, - HostTelemetryData? host, - ICollection? configuration, - ICollection? dependencies, - ICollection? integrations, - bool sendHeartbeat) - { - if (application is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(application)); - } - - if (host is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(host)); - } - - if (configuration is not null) - { - Log.Debug("App initialized, sending app-started"); - var payload = new AppStartedPayload( - configuration: configuration, - dependencies: dependencies, - integrations: integrations); - - return new[] { GetRequest(application, host, TelemetryRequestTypes.AppStarted, payload) }; - } - - if (dependencies is not null && integrations is not null) - { - Log.Debug("Dependencies updated, sending app-dependencies-loaded"); - Log.Debug("Integrations updated, sending app-integrations-change"); - var depsPayload = new AppDependenciesLoadedPayload(dependencies: dependencies); - var integrationsPayload = new AppIntegrationsChangedPayload(integrations: integrations); - - return new[] - { - GetRequest(application, host, TelemetryRequestTypes.AppDependenciesLoaded, depsPayload), - GetRequest(application, host, TelemetryRequestTypes.AppIntegrationsChanged, integrationsPayload), - }; - } - - if (integrations is not null) - { - Log.Debug("Integrations updated, sending app-integrations-change"); - var payload = new AppIntegrationsChangedPayload(integrations: integrations); - - return new[] { GetRequest(application, host, TelemetryRequestTypes.AppIntegrationsChanged, payload), }; - } - - if (dependencies is not null) - { - Log.Debug("Dependencies updated, sending app-dependencies-loaded"); - var payload = new AppDependenciesLoadedPayload(dependencies: dependencies); - - return new[] { GetRequest(application, host, TelemetryRequestTypes.AppDependenciesLoaded, payload), }; - } - - if (sendHeartbeat) - { - Log.Debug("No changes in telemetry, sending heartbeat"); - return new[] { GetRequest(application, host, TelemetryRequestTypes.AppHeartbeat, payload: null) }; - } - - Log.Debug("No changes in telemetry"); - return Array.Empty(); - } - - public TelemetryData BuildAppClosingTelemetryData(ApplicationTelemetryData? application, HostTelemetryData? host) - { - if (application is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(application)); - } - - if (host is null) - { - ThrowHelper.ThrowArgumentNullException(nameof(host)); - } - - return GetRequest(application, host, TelemetryRequestTypes.AppClosing, payload: null); - } - - private TelemetryData GetRequest( - ApplicationTelemetryData application, - HostTelemetryData host, - string requestType, - IPayload? payload) - { - var sequence = Interlocked.Increment(ref _sequence); - - return new TelemetryData( - requestType: requestType, - tracerTime: DateTimeOffset.UtcNow.ToUnixTimeSeconds(), - runtimeId: DistributedTracer.Instance.GetRuntimeId(), - seqId: sequence, - application: application, - host: host, - payload: payload); - } - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/TelemetryFactory.cs b/tracer/src/Datadog.Trace/Telemetry/TelemetryFactory.cs index e40cb1993..5b9114672 100644 --- a/tracer/src/Datadog.Trace/Telemetry/TelemetryFactory.cs +++ b/tracer/src/Datadog.Trace/Telemetry/TelemetryFactory.cs @@ -2,44 +2,19 @@ // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // + +// Modified by Splunk Inc. + #nullable enable using System; using Datadog.Trace.Configuration; -using Datadog.Trace.Logging; -using Datadog.Trace.Telemetry.Transports; namespace Datadog.Trace.Telemetry { internal class TelemetryFactory { - private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(); - - private static readonly ConfigurationTelemetryCollector Configuration = new(); - private static readonly DependencyTelemetryCollector Dependencies = new(); - private static readonly IntegrationTelemetryCollector Integrations = new(); - internal static ITelemetryController CreateTelemetryController(ImmutableTracerSettings tracerSettings) { - var settings = TelemetrySettings.FromDefaultSources(); - if (settings.TelemetryEnabled) - { - try - { - var factory = TelemetryTransportFactory.Create(settings, tracerSettings.ExporterSettings); - - return new TelemetryController( - Configuration, - Dependencies, - Integrations, - factory, - TelemetryConstants.RefreshInterval); - } - catch (Exception ex) - { - Log.Warning(ex, "Error initializing telemetry. Telemetry collection disabled."); - } - } - return NullTelemetryController.Instance; } } diff --git a/tracer/src/Datadog.Trace/Telemetry/TelemetryHttpHeaderNames.cs b/tracer/src/Datadog.Trace/Telemetry/TelemetryHttpHeaderNames.cs deleted file mode 100644 index 2ac44b70e..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/TelemetryHttpHeaderNames.cs +++ /dev/null @@ -1,34 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System.Collections.Generic; -using Datadog.Trace.Propagation; - -namespace Datadog.Trace.Telemetry -{ - internal static class TelemetryHttpHeaderNames - { - /// - /// Gets the default constant headers that should be added to any request to the agent - /// - internal static KeyValuePair[] GetDefaultAgentHeaders() - => new[] - { - new KeyValuePair(DDHttpHeaderNames.TracingEnabled, "false"), // don't add automatic instrumentation to requests directed to the agent - }; - - /// - /// Gets the default constant headers that should be added to any request to the direct telemetry intake - /// - internal static KeyValuePair[] GetDefaultIntakeHeaders(string apiKey) - => new[] - { - new KeyValuePair(DDHttpHeaderNames.TracingEnabled, "false"), // don't add automatic instrumentation to requests directed to the agent - new KeyValuePair(TelemetryConstants.ApiKeyHeader, apiKey), - }; - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/TelemetryPushResult.cs b/tracer/src/Datadog.Trace/Telemetry/TelemetryPushResult.cs deleted file mode 100644 index 6a6525456..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/TelemetryPushResult.cs +++ /dev/null @@ -1,17 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -namespace Datadog.Trace.Telemetry -{ - /// - /// The result of attempting to push telemetry to the agent - /// - internal enum TelemetryPushResult - { - Success, - TransientFailure, - FatalError - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/TelemetryRequestTypes.cs b/tracer/src/Datadog.Trace/Telemetry/TelemetryRequestTypes.cs deleted file mode 100644 index d8d903f7c..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/TelemetryRequestTypes.cs +++ /dev/null @@ -1,18 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -namespace Datadog.Trace.Telemetry -{ - internal static class TelemetryRequestTypes - { - public const string AppStarted = "app-started"; - public const string AppDependenciesLoaded = "app-dependencies-loaded"; - public const string AppIntegrationsChanged = "app-integrations-change"; - public const string AppHeartbeat = "app-heartbeat"; - public const string AppClosing = "app-closing"; - - public const string GenerateMetrics = "generate-metrics"; - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/TelemetrySettings.cs b/tracer/src/Datadog.Trace/Telemetry/TelemetrySettings.cs deleted file mode 100644 index 2e479e974..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/TelemetrySettings.cs +++ /dev/null @@ -1,121 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -#nullable enable - -using System; -using Datadog.Trace.Configuration; -using Datadog.Trace.Util; - -namespace Datadog.Trace.Telemetry -{ - internal class TelemetrySettings - { - public TelemetrySettings(bool telemetryEnabled, string? configurationError, AgentlessSettings? agentlessSettings) - { - TelemetryEnabled = telemetryEnabled; - ConfigurationError = configurationError; - Agentless = agentlessSettings; - } - - /// - /// Gets a value indicating whether internal telemetry is enabled - /// - /// - public bool TelemetryEnabled { get; } - - public string? ConfigurationError { get; } - - public AgentlessSettings? Agentless { get; } - - public static TelemetrySettings FromDefaultSources() => FromSource(GlobalSettings.CreateDefaultConfigurationSource()); - - public static TelemetrySettings FromSource(IConfigurationSource? source) - { - string? configurationError = null; - - var apiKey = source?.GetString(ConfigurationKeys.ApiKey); - var agentlessExplicitlyEnabled = source?.GetBool(ConfigurationKeys.Telemetry.AgentlessEnabled); - - var agentlessEnabled = false; - - if (agentlessExplicitlyEnabled == true) - { - if (string.IsNullOrEmpty(apiKey)) - { - configurationError = "Telemetry configuration error: Agentless mode was enabled, but no API key was available."; - } - else - { - agentlessEnabled = true; - } - } - else if (agentlessExplicitlyEnabled is null) - { - // if there's an API key, we use agentless mode, otherwise we use the agent - agentlessEnabled = !string.IsNullOrEmpty(apiKey); - } - - // disabled by default unless using agentless - var telemetryEnabled = source?.GetBool(ConfigurationKeys.Telemetry.Enabled) - ?? agentlessEnabled; - - AgentlessSettings? agentless = null; - if (telemetryEnabled && agentlessEnabled) - { - // We have an API key, so try to send directly to intake - Uri agentlessUri; - - var requestedTelemetryUri = source?.GetString(ConfigurationKeys.Telemetry.Uri); - if (!string.IsNullOrEmpty(requestedTelemetryUri) - && Uri.TryCreate(requestedTelemetryUri, UriKind.Absolute, out var telemetryUri)) - { - // telemetry URI provided and well-formed - agentlessUri = UriHelpers.Combine(telemetryUri, "/"); - } - else - { - if (!string.IsNullOrEmpty(requestedTelemetryUri)) - { - // URI parsing failed - configurationError = configurationError is null - ? $"Telemetry configuration error: The provided telemetry Uri '{requestedTelemetryUri}' was not a valid absolute Uri. Using default intake Uri." - : configurationError + ", The provided telemetry Uri '{requestedTelemetryUri}' was not a valid absolute Uri. Using default intake Uri."; - } - - // use the default intake. Use SIGNALFX_SITE if provided, otherwise use default - var siteFromEnv = source?.GetString(ConfigurationKeys.Site); - var ddSite = string.IsNullOrEmpty(siteFromEnv) ? "datadoghq.com" : siteFromEnv; - agentlessUri = new Uri($"{TelemetryConstants.TelemetryIntakePrefix}.{ddSite}/"); - } - - agentless = new AgentlessSettings(agentlessUri, apiKey!); - } - - return new TelemetrySettings(telemetryEnabled, configurationError, agentless); - } - - public class AgentlessSettings - { - public AgentlessSettings(Uri agentlessUri, string apiKey) - { - AgentlessUri = agentlessUri; - ApiKey = apiKey; - } - - /// - /// Gets the URL to send agentless telemetry - /// - public Uri AgentlessUri { get; } - - /// - /// Gets the api key to use when sending requests to the agentless telemetry intake - /// - public string ApiKey { get; } - } - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/Transports/JsonTelemetryTransport.cs b/tracer/src/Datadog.Trace/Telemetry/Transports/JsonTelemetryTransport.cs deleted file mode 100644 index 1f2385039..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/Transports/JsonTelemetryTransport.cs +++ /dev/null @@ -1,95 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Net; -using System.Net.Sockets; -using System.Text; -using System.Threading.Tasks; -using Datadog.Trace.Agent; -using Datadog.Trace.Logging; -using Datadog.Trace.Vendors.Newtonsoft.Json; -using Datadog.Trace.Vendors.Newtonsoft.Json.Serialization; - -namespace Datadog.Trace.Telemetry.Transports -{ - internal class JsonTelemetryTransport : ITelemetryTransport - { - private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(); - internal static readonly JsonSerializerSettings SerializerSettings = new() - { - NullValueHandling = NullValueHandling.Ignore, - ContractResolver = new DefaultContractResolver { NamingStrategy = new SnakeCaseNamingStrategy(), } - }; - - private readonly IApiRequestFactory _requestFactory; - private readonly Uri _endpoint; - - public JsonTelemetryTransport(IApiRequestFactory requestFactory) - { - _requestFactory = requestFactory; - _endpoint = _requestFactory.GetEndpoint(TelemetryConstants.TelemetryPath); - } - - public async Task PushTelemetry(TelemetryData data) - { - try - { - // have to buffer in memory so we know the content length - var serializedData = SerializeTelemetry(data); - var bytes = Encoding.UTF8.GetBytes(serializedData); - - var request = _requestFactory.Create(_endpoint); - - request.AddHeader(TelemetryConstants.ApiVersionHeader, data.ApiVersion); - request.AddHeader(TelemetryConstants.RequestTypeHeader, data.RequestType); - - using var response = await request.PostAsync(new ArraySegment(bytes), "application/json").ConfigureAwait(false); - if (response.StatusCode is >= 200 and < 300) - { - Log.Debug("Telemetry sent successfully"); - return TelemetryPushResult.Success; - } - else if (response.StatusCode == 404) - { - Log.Debug("Error sending telemetry: 404. Disabling further telemetry, as endpoint '{Endpoint}' not found", _requestFactory.Info(_endpoint)); - return TelemetryPushResult.FatalError; - } - else - { - Log.Debug("Error sending telemetry to '{Endpoint}' {StatusCode} ", _requestFactory.Info(_endpoint), response.StatusCode); - return TelemetryPushResult.TransientFailure; - } - } - catch (Exception ex) when (IsFatalException(ex)) - { - Log.Warning(ex, "Error sending telemetry data, unable to communicate with '{Endpoint}'", _requestFactory.Info(_endpoint)); - return TelemetryPushResult.FatalError; - } - catch (Exception ex) - { - Log.Warning(ex, "Error sending telemetry data to '{Endpoint}'", _requestFactory.Info(_endpoint)); - return TelemetryPushResult.TransientFailure; - } - } - - // Internal for testing - internal static string SerializeTelemetry(TelemetryData data) - { - return JsonConvert.SerializeObject(data, Formatting.None, SerializerSettings); - } - - private static bool IsFatalException(Exception ex) - { - return ex is SocketException -#if !NETFRAMEWORK - or WebException { InnerException: System.Net.Http.HttpRequestException { InnerException: SocketException } } - or System.Net.Http.HttpRequestException { InnerException: SocketException } -#endif - or WebException { Response: HttpWebResponse { StatusCode: HttpStatusCode.NotFound } } - or WebException { InnerException: SocketException }; - } - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/Transports/TelemetryTransportFactory.cs b/tracer/src/Datadog.Trace/Telemetry/Transports/TelemetryTransportFactory.cs deleted file mode 100644 index 2ccb4c8aa..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/Transports/TelemetryTransportFactory.cs +++ /dev/null @@ -1,27 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -#nullable enable - -using Datadog.Trace.Configuration; - -namespace Datadog.Trace.Telemetry.Transports -{ - internal class TelemetryTransportFactory - { - public static ITelemetryTransport Create( - TelemetrySettings telemetrySettings, - ImmutableExporterSettings exporterSettings) - { - var requestFactory = telemetrySettings switch - { - { Agentless: { } a } => TelemetryTransportStrategy.GetDirectIntakeFactory(a.AgentlessUri, a.ApiKey), - _ => TelemetryTransportStrategy.GetAgentIntakeFactory(exporterSettings), - }; - - return new JsonTelemetryTransport(requestFactory); - } - } -} diff --git a/tracer/src/Datadog.Trace/Telemetry/Transports/TelemetryTransportStrategy.cs b/tracer/src/Datadog.Trace/Telemetry/Transports/TelemetryTransportStrategy.cs deleted file mode 100644 index 9e75769da..000000000 --- a/tracer/src/Datadog.Trace/Telemetry/Transports/TelemetryTransportStrategy.cs +++ /dev/null @@ -1,57 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using Datadog.Trace.Agent; -using Datadog.Trace.Agent.StreamFactories; -using Datadog.Trace.Agent.Transports; -using Datadog.Trace.Configuration; -using Datadog.Trace.HttpOverStreams; -using Datadog.Trace.Logging; -using Datadog.Trace.Util; - -namespace Datadog.Trace.Telemetry.Transports; - -internal static class TelemetryTransportStrategy -{ - private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(); - private static readonly TimeSpan Timeout = TimeSpan.FromSeconds(15); - - public static IApiRequestFactory GetDirectIntakeFactory(Uri baseEndpoint, string apiKey) - { -#if NETCOREAPP - Log.Information("Using {FactoryType} for telemetry transport direct to intake.", nameof(HttpClientRequestFactory)); - return new HttpClientRequestFactory(baseEndpoint, TelemetryHttpHeaderNames.GetDefaultIntakeHeaders(apiKey), timeout: Timeout); -#else - Log.Information("Using {FactoryType} for telemetry transport direct to intake.", nameof(ApiWebRequestFactory)); - return new ApiWebRequestFactory(baseEndpoint, TelemetryHttpHeaderNames.GetDefaultIntakeHeaders(apiKey), timeout: Timeout); -#endif - } - - public static IApiRequestFactory GetAgentIntakeFactory(ImmutableExporterSettings settings) - { - // use the same transport for telemetry as we do for traces - var strategy = settings.TracesTransport; - - switch (strategy) - { - case TracesTransportType.WindowsNamedPipe: - Log.Information("Using {FactoryType} for telemetry transport, with pipe name {PipeName} and timeout {Timeout}ms.", nameof(NamedPipeClientStreamFactory), settings.TracesPipeName, settings.TracesPipeTimeoutMs); - return new HttpStreamRequestFactory(new NamedPipeClientStreamFactory(settings.TracesPipeName, settings.TracesPipeTimeoutMs), DatadogHttpClient.CreateTelemetryAgentClient(), GetBaseEndpoint()); - case TracesTransportType.Default: - default: - var agentUri = UriHelpers.Combine(settings.AgentUri, TelemetryConstants.AgentTelemetryEndpoint); -#if NETCOREAPP - Log.Information("Using {FactoryType} for telemetry transport.", nameof(HttpClientRequestFactory)); - return new HttpClientRequestFactory(agentUri, TelemetryHttpHeaderNames.GetDefaultAgentHeaders(), timeout: Timeout); -#else - Log.Information("Using {FactoryType} for telemetry transport.", nameof(ApiWebRequestFactory)); - return new ApiWebRequestFactory(agentUri, TelemetryHttpHeaderNames.GetDefaultAgentHeaders(), timeout: Timeout); -#endif - } - - static Uri GetBaseEndpoint() => new Uri("http://localhost/" + TelemetryConstants.AgentTelemetryEndpoint); - } -} diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AWS/AwsSqsTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AWS/AwsSqsTests.cs index b72a06dd5..549795120 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AWS/AwsSqsTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AWS/AwsSqsTests.cs @@ -34,7 +34,6 @@ public AwsSqsTests(ITestOutputHelper output) [Trait("Category", "EndToEnd")] public async Task SubmitsTraces(string packageVersion) { - using var telemetry = this.ConfigureTelemetry(); using (var agent = EnvironmentHelper.GetMockAgent()) using (RunSampleAndWaitForExit(agent, packageVersion: packageVersion)) { @@ -69,8 +68,6 @@ public async Task SubmitsTraces(string packageVersion) // - GetQueueUrl // - PurgeQueue await VerifyHelper.VerifySpans(spans, settings); - - telemetry.AssertIntegrationEnabled(IntegrationId.AwsSqs); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/FakeCommandTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/FakeCommandTests.cs index 42b6a55cf..0daf150b0 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/FakeCommandTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/FakeCommandTests.cs @@ -40,7 +40,6 @@ public void SubmitsTraces() const string expectedOperationName = dbType + ".query"; const string expectedServiceName = "Samples.FakeDbCommand"; - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using var process = RunSampleAndWaitForExit(agent); var spans = agent.WaitForSpans(expectedSpanCount, operationName: expectedOperationName); @@ -55,8 +54,6 @@ public void SubmitsTraces() Assert.Equal(expectedServiceName, span.Service); } - - telemetry.AssertIntegrationEnabled(IntegrationId.AdoNet); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MicrosoftDataSqlClientTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MicrosoftDataSqlClientTests.cs index 71435805b..8ed70a4f5 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MicrosoftDataSqlClientTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MicrosoftDataSqlClientTests.cs @@ -63,7 +63,6 @@ public void SubmitsTraces(string packageVersion) const string expectedOperationName = dbType + ".query"; const string expectedServiceName = "Samples.Microsoft.Data.SqlClient"; - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using var process = RunSampleAndWaitForExit(agent, packageVersion: packageVersion); var spans = agent.WaitForSpans(expectedSpanCount, operationName: expectedOperationName); @@ -78,8 +77,6 @@ public void SubmitsTraces(string packageVersion) Assert.Equal(expectedServiceName, span.Service); } - - telemetry.AssertIntegrationEnabled(IntegrationId.SqlClient); } [SkippableFact] @@ -93,14 +90,12 @@ public void IntegrationDisabled() SetEnvironmentVariable($"SIGNALFX_TRACE_{nameof(IntegrationId.SqlClient)}_ENABLED", "false"); string packageVersion = PackageVersions.MicrosoftDataSqlClient.First()[0] as string; - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using var process = RunSampleAndWaitForExit(agent, packageVersion: packageVersion); var spans = agent.WaitForSpans(totalSpanCount, returnAllOperations: true); Assert.NotEmpty(spans); Assert.Empty(spans.Where(s => s.Name.Equals(expectedOperationName))); - telemetry.AssertIntegrationDisabled(IntegrationId.SqlClient); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MicrosoftDataSqliteTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MicrosoftDataSqliteTests.cs index 1e1e194db..051649c9b 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MicrosoftDataSqliteTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MicrosoftDataSqliteTests.cs @@ -44,7 +44,6 @@ public void SubmitsTraces(string packageVersion) const string expectedOperationName = dbType + ".query"; const string expectedServiceName = "Samples.Microsoft.Data.Sqlite"; - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using var process = RunSampleAndWaitForExit(agent, packageVersion: packageVersion); var spans = agent.WaitForSpans(expectedSpanCount, operationName: expectedOperationName); @@ -58,8 +57,6 @@ public void SubmitsTraces(string packageVersion) Assert.Equal(expectedServiceName, span.Service); } - - telemetry.AssertIntegrationEnabled(IntegrationId.Sqlite); } [SkippableFact] @@ -73,7 +70,6 @@ public void IntegrationDisabled() SetEnvironmentVariable($"SIGNALFX_TRACE_{nameof(IntegrationId.Sqlite)}_ENABLED", "false"); - using var telemetry = this.ConfigureTelemetry(); string packageVersion = PackageVersions.MicrosoftDataSqlite.First()[0] as string; using var agent = EnvironmentHelper.GetMockAgent(); using var process = RunSampleAndWaitForExit(agent, packageVersion: packageVersion); @@ -81,7 +77,6 @@ public void IntegrationDisabled() Assert.NotEmpty(spans); Assert.Empty(spans.Where(s => s.Name.Equals(expectedOperationName))); - telemetry.AssertIntegrationDisabled(IntegrationId.Sqlite); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MySqlCommandTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MySqlCommandTests.cs index 441b8700b..5a802d6ab 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MySqlCommandTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MySqlCommandTests.cs @@ -77,7 +77,6 @@ public void IntegrationDisabled() SetEnvironmentVariable($"SIGNALFX_TRACE_{nameof(IntegrationId.MySql)}_ENABLED", "false"); - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); // don't use the first package version which is 6.x and is not supported on ARM64. @@ -88,7 +87,6 @@ public void IntegrationDisabled() Assert.NotEmpty(spans); Assert.Empty(spans.Where(s => s.Name.Equals(expectedOperationName))); - telemetry.AssertIntegrationDisabled(IntegrationId.MySql); } private void SubmitsTraces(string packageVersion) @@ -114,7 +112,6 @@ private void SubmitsTraces(string packageVersion) const string expectedOperationName = dbType + ".query"; const string expectedServiceName = "Samples.MySql"; - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using var process = RunSampleAndWaitForExit(agent, packageVersion: packageVersion); var spans = agent.WaitForSpans(expectedSpanCount, operationName: expectedOperationName); @@ -129,8 +126,6 @@ private void SubmitsTraces(string packageVersion) Assert.Equal(expectedServiceName, span.Service); } - - telemetry.AssertIntegrationEnabled(IntegrationId.MySql); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MySqlConnectorTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MySqlConnectorTests.cs index 553888f27..d336ad63d 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MySqlConnectorTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MySqlConnectorTests.cs @@ -49,7 +49,6 @@ public void SubmitsTraces(string packageVersion) const string expectedOperationName = dbType + ".query"; const string expectedServiceName = "Samples.MySqlConnector"; - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using var process = RunSampleAndWaitForExit(agent, packageVersion: packageVersion); var spans = agent.WaitForSpans(expectedSpanCount, operationName: expectedOperationName); @@ -64,8 +63,6 @@ public void SubmitsTraces(string packageVersion) Assert.Equal(expectedServiceName, span.Service); } - - telemetry.AssertIntegrationEnabled(IntegrationId.MySql); } [SkippableFact] @@ -77,7 +74,6 @@ public void IntegrationDisabled() SetEnvironmentVariable($"SIGNALFX_TRACE_{nameof(IntegrationId.MySql)}_ENABLED", "false"); - using var telemetry = this.ConfigureTelemetry(); string packageVersion = PackageVersions.MySqlConnector.First()[0] as string; using var agent = EnvironmentHelper.GetMockAgent(); using var process = RunSampleAndWaitForExit(agent, packageVersion: packageVersion); @@ -85,7 +81,6 @@ public void IntegrationDisabled() Assert.NotEmpty(spans); Assert.Empty(spans.Where(s => s.Name.Equals(expectedOperationName))); - telemetry.AssertIntegrationDisabled(IntegrationId.MySql); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/NpgsqlCommandTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/NpgsqlCommandTests.cs index 3767ff878..efaa1834d 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/NpgsqlCommandTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/NpgsqlCommandTests.cs @@ -47,7 +47,6 @@ public void SubmitsTraces(string packageVersion) const string expectedOperationName = dbType + ".query"; const string expectedServiceName = "Samples.Npgsql"; - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using var process = RunSampleAndWaitForExit(agent, packageVersion: packageVersion); var spans = agent.WaitForSpans(expectedSpanCount, operationName: expectedOperationName); @@ -63,8 +62,6 @@ public void SubmitsTraces(string packageVersion) Assert.Equal(expectedServiceName, span.Service); } - - telemetry.AssertIntegrationEnabled(IntegrationId.Npgsql); } [SkippableFact] @@ -77,14 +74,12 @@ public void IntegrationDisabled() SetEnvironmentVariable($"SIGNALFX_TRACE_{nameof(IntegrationId.Npgsql)}_ENABLED", "false"); string packageVersion = PackageVersions.Npgsql.First()[0] as string; - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using var process = RunSampleAndWaitForExit(agent, packageVersion: packageVersion); var spans = agent.WaitForSpans(totalSpanCount, returnAllOperations: true); Assert.NotEmpty(spans); Assert.Empty(spans.Where(s => s.Name.Equals(expectedOperationName))); - telemetry.AssertIntegrationDisabled(IntegrationId.Npgsql); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/SqlCommand20Tests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/SqlCommand20Tests.cs index f7f1fa0d4..ec46047b2 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/SqlCommand20Tests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/SqlCommand20Tests.cs @@ -33,7 +33,6 @@ public void SubmitsTraces() const string expectedOperationName = dbType + ".query"; const string expectedServiceName = "Samples.SqlServer.NetFramework20"; - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using var process = RunSampleAndWaitForExit(agent); var spans = agent.WaitForSpans(expectedSpanCount, operationName: expectedOperationName); @@ -47,8 +46,6 @@ public void SubmitsTraces() Assert.Equal(expectedServiceName, span.Service); } - - telemetry.AssertIntegrationEnabled(IntegrationId.SqlClient); } [SkippableFact] @@ -61,14 +58,12 @@ public void IntegrationDisabled() SetEnvironmentVariable($"SIGNALFX_TRACE_{nameof(IntegrationId.SqlClient)}_ENABLED", "false"); - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using var process = RunSampleAndWaitForExit(agent); var spans = agent.WaitForSpans(totalSpanCount, returnAllOperations: true); Assert.NotEmpty(spans); Assert.Empty(spans.Where(s => s.Name.Equals(expectedOperationName))); - telemetry.AssertIntegrationDisabled(IntegrationId.SqlClient); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/SystemDataSqlClientTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/SystemDataSqlClientTests.cs index e133d0a8e..d33eeb11d 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/SystemDataSqlClientTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/SystemDataSqlClientTests.cs @@ -54,7 +54,6 @@ public void SubmitsTraces(string packageVersion) const string expectedOperationName = dbType + ".query"; const string expectedServiceName = "Samples.SqlServer"; - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using var process = RunSampleAndWaitForExit(agent, packageVersion: packageVersion); var spans = agent.WaitForSpans(expectedSpanCount, operationName: expectedOperationName); @@ -68,8 +67,6 @@ public void SubmitsTraces(string packageVersion) Assert.Equal(expectedServiceName, span.Service); } - - telemetry.AssertIntegrationEnabled(IntegrationId.SqlClient); } [SkippableFact] @@ -83,14 +80,12 @@ public void IntegrationDisabled() SetEnvironmentVariable($"SIGNALFX_TRACE_{nameof(IntegrationId.SqlClient)}_ENABLED", "false"); string packageVersion = PackageVersions.SystemDataSqlClient.First()[0] as string; - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using var process = RunSampleAndWaitForExit(agent, packageVersion: packageVersion); var spans = agent.WaitForSpans(totalSpanCount, returnAllOperations: true); Assert.NotEmpty(spans); Assert.Empty(spans.Where(s => s.Name.Equals(expectedOperationName))); - telemetry.AssertIntegrationDisabled(IntegrationId.SqlClient); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/SystemDataSqliteTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/SystemDataSqliteTests.cs index 5265a9ed0..7358faeb3 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/SystemDataSqliteTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/SystemDataSqliteTests.cs @@ -33,7 +33,6 @@ public void SubmitsTraces() const string expectedOperationName = dbType + ".query"; const string expectedServiceName = "Samples.SQLite.Core"; - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using var process = RunSampleAndWaitForExit(agent); var spans = agent.WaitForSpans(expectedSpanCount, operationName: expectedOperationName); @@ -47,8 +46,6 @@ public void SubmitsTraces() Assert.Equal(expectedServiceName, span.Service); } - - telemetry.AssertIntegrationEnabled(IntegrationId.Sqlite); } [SkippableFact] @@ -61,14 +58,12 @@ public void IntegrationDisabled() const string expectedOperationName = "sqlite.query"; SetEnvironmentVariable($"SIGNALFX_TRACE_{nameof(IntegrationId.Sqlite)}_ENABLED", "false"); - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using var process = RunSampleAndWaitForExit(agent); var spans = agent.WaitForSpans(totalSpanCount, returnAllOperations: true); Assert.NotEmpty(spans); Assert.Empty(spans.Where(s => s.Name.Equals(expectedOperationName))); - telemetry.AssertIntegrationDisabled(IntegrationId.Sqlite); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AerospikeTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AerospikeTests.cs index ac8f3db0b..5ea4ec2d4 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AerospikeTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AerospikeTests.cs @@ -31,7 +31,6 @@ public AerospikeTests(ITestOutputHelper output) [Trait("Category", "ArmUnsupported")] public async Task SubmitTraces(string packageVersion) { - using var telemetry = this.ConfigureTelemetry(); using (var agent = EnvironmentHelper.GetMockAgent()) using (RunSampleAndWaitForExit(agent, packageVersion: packageVersion)) { @@ -58,8 +57,6 @@ public async Task SubmitTraces(string packageVersion) await VerifyHelper.VerifySpans(spans, settings) .DisableRequireUniquePrefix() .UseFileName(nameof(AerospikeTests)); - - telemetry.AssertIntegrationEnabled(IntegrationId.Aerospike); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CI/MsTestV2Tests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CI/MsTestV2Tests.cs deleted file mode 100644 index edc963a9d..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CI/MsTestV2Tests.cs +++ /dev/null @@ -1,337 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Datadog.Trace.Ci; -using Datadog.Trace.Ci.Tags; -using Datadog.Trace.TestHelpers; -using Xunit; -using Xunit.Abstractions; - -namespace Datadog.Trace.ClrProfiler.IntegrationTests.CI -{ - public class MsTestV2Tests : TestHelper - { - private const string TestSuiteName = "Samples.MSTestTests.TestSuite"; - private const string TestBundleName = "Samples.MSTestTests"; - - public MsTestV2Tests(ITestOutputHelper output) - : base("MSTestTests", output) - { - SetServiceVersion("1.0.0"); - } - - [SkippableTheory] - [MemberData(nameof(PackageVersions.MSTest), MemberType = typeof(PackageVersions))] - [Trait("Category", "EndToEnd")] - [Trait("Category", "TestIntegrations")] - public void SubmitTraces(string packageVersion) - { - var version = string.IsNullOrEmpty(packageVersion) ? new Version("2.2.8") : new Version(packageVersion); - List spans = null; - var expectedSpanCount = version.CompareTo(new Version("2.2.5")) < 0 ? 13 : 15; - - try - { - SetEnvironmentVariable("SIGNALFX_CIVISIBILITY_ENABLED", "1"); - SetEnvironmentVariable("SIGNALFX_TRACE_DEBUG", "1"); - SetEnvironmentVariable("SIGNALFX_DUMP_ILREWRITE_ENABLED", "1"); - - using (var agent = EnvironmentHelper.GetMockAgent()) - using (ProcessResult processResult = RunDotnetTestSampleAndWaitForExit(agent, packageVersion: packageVersion)) - { - spans = agent.WaitForSpans(expectedSpanCount) - .Where(s => !(s.Tags.TryGetValue(Tags.InstrumentationName, out var sValue) && sValue == "HttpMessageHandler")) - .ToList(); - - // Check the span count - Assert.Equal(expectedSpanCount, spans.Count); - - foreach (var targetSpan in spans) - { - // check the name - Assert.Equal("mstest.test", targetSpan.Name); - - // check the CIEnvironmentValues decoration. - CheckCIEnvironmentValuesDecoration(targetSpan); - - // check the runtime values - CheckRuntimeValues(targetSpan); - - // check the bundle name - AssertTargetSpanEqual(targetSpan, TestTags.Bundle, TestBundleName); - - // check the suite name - AssertTargetSpanEqual(targetSpan, TestTags.Suite, TestSuiteName); - - // check the test type - AssertTargetSpanEqual(targetSpan, TestTags.Type, TestTags.TypeTest); - - // check the test framework - AssertTargetSpanContains(targetSpan, TestTags.Framework, "MSTestV2"); - Assert.True(targetSpan.Tags.Remove(TestTags.FrameworkVersion)); - - // check the version - AssertTargetSpanEqual(targetSpan, "version", "1.0.0"); - - // check the SignalFx library name - AssertTargetSpanEqual(targetSpan, "signalfx.tracing.library", "dotnet-tracing"); - - // check the SignalFx library version - AssertTargetSpanEqual(targetSpan, "signalfx.tracing.version", "1.1.0.0"); - - // checks the runtime id tag - AssertTargetSpanExists(targetSpan, Tags.RuntimeId); - - // checks the source tags - AssertTargetSpanExists(targetSpan, TestTags.SourceFile); - - // checks code owners - AssertTargetSpanExists(targetSpan, TestTags.CodeOwners); - - // checks the origin tag - CheckOriginTag(targetSpan); - - // Check the Environment - AssertTargetSpanEqual(targetSpan, Tags.Env, "integration_tests"); - - // Language - AssertTargetSpanEqual(targetSpan, Tags.Language, TracerConstants.Language); - - // CI Library Language - AssertTargetSpanEqual(targetSpan, CommonTags.LibraryVersion, TracerConstants.AssemblyVersion); - - // check specific test span - switch (targetSpan.Tags[TestTags.Name]) - { - case "SimplePassTest": - CheckSimpleTestSpan(targetSpan); - break; - - case "SimpleSkipFromAttributeTest": - CheckSimpleSkipFromAttributeTest(targetSpan); - break; - - case "SimpleErrorTest": - CheckSimpleErrorTest(targetSpan); - break; - - case "TraitPassTest": - CheckSimpleTestSpan(targetSpan); - CheckTraitsValues(targetSpan); - break; - - case "TraitSkipFromAttributeTest": - CheckSimpleSkipFromAttributeTest(targetSpan); - CheckTraitsValues(targetSpan); - break; - - case "TraitErrorTest": - CheckSimpleErrorTest(targetSpan); - CheckTraitsValues(targetSpan); - break; - - case "SimpleParameterizedTest": - CheckSimpleTestSpan(targetSpan); - AssertTargetSpanAnyOf( - targetSpan, - TestTags.Parameters, - "{\"metadata\":{},\"arguments\":{\"xValue\":\"1\",\"yValue\":\"1\",\"expectedResult\":\"2\"}}", - "{\"metadata\":{},\"arguments\":{\"xValue\":\"2\",\"yValue\":\"2\",\"expectedResult\":\"4\"}}", - "{\"metadata\":{},\"arguments\":{\"xValue\":\"3\",\"yValue\":\"3\",\"expectedResult\":\"6\"}}"); - break; - - case "SimpleSkipParameterizedTest": - CheckSimpleSkipFromAttributeTest(targetSpan); - // On callsite the parameters tags are being sent with no parameters, this is not required due the whole test is skipped. - // That behavior has changed in calltarget. - AssertTargetSpanAnyOf( - targetSpan, - TestTags.Parameters, - "{\"metadata\":{},\"arguments\":{\"xValue\":\"(default)\",\"yValue\":\"(default)\",\"expectedResult\":\"(default)\"}}"); - break; - - case "SimpleErrorParameterizedTest": - CheckSimpleErrorTest(targetSpan); - AssertTargetSpanAnyOf( - targetSpan, - TestTags.Parameters, - "{\"metadata\":{},\"arguments\":{\"xValue\":\"1\",\"yValue\":\"0\",\"expectedResult\":\"2\"}}", - "{\"metadata\":{},\"arguments\":{\"xValue\":\"2\",\"yValue\":\"0\",\"expectedResult\":\"4\"}}", - "{\"metadata\":{},\"arguments\":{\"xValue\":\"3\",\"yValue\":\"0\",\"expectedResult\":\"6\"}}"); - break; - } - - // check remaining tag (only the name) - Assert.Single(targetSpan.Tags); - } - } - } - catch - { - WriteSpans(spans); - throw; - } - } - - private static void WriteSpans(List spans) - { - if (spans is null || spans.Count == 0) - { - return; - } - - Console.WriteLine("***********************************"); - - int i = 0; - foreach (var span in spans) - { - Console.Write($" {i++}) "); - Console.Write($"TraceId={span.TraceId}, "); - Console.Write($"SpanId={span.SpanId}, "); - Console.Write($"Service={span.Service}, "); - Console.Write($"Name={span.Name}, "); - Console.Write($"Resource={span.Resource}, "); - Console.Write($"Type={span.Type}, "); - Console.Write($"Error={span.Error}"); - Console.WriteLine(); - Console.WriteLine($" Tags="); - foreach (var kv in span.Tags) - { - Console.WriteLine($" => {kv.Key} = {kv.Value}"); - } - - Console.WriteLine(); - } - - Console.WriteLine("***********************************"); - } - - private static void AssertTargetSpanAnyOf(MockSpan targetSpan, string key, params string[] values) - { - string actualValue = targetSpan.Tags[key]; - Assert.Contains(actualValue, values); - targetSpan.Tags.Remove(key); - } - - private static void AssertTargetSpanEqual(MockSpan targetSpan, string key, string value) - { - Assert.Equal(value, targetSpan.Tags[key]); - targetSpan.Tags.Remove(key); - } - - private static void AssertTargetSpanExists(MockSpan targetSpan, string key) - { - Assert.True(targetSpan.Tags.ContainsKey(key)); - targetSpan.Tags.Remove(key); - } - - private static void AssertTargetSpanContains(MockSpan targetSpan, string key, string value) - { - Assert.Contains(value, targetSpan.Tags[key]); - targetSpan.Tags.Remove(key); - } - - private static void CheckCIEnvironmentValuesDecoration(MockSpan targetSpan) - { - var context = new SpanContext(null, null, null, null); - var span = new Span(context, DateTimeOffset.UtcNow); - CIEnvironmentValues.Instance.DecorateSpan(span); - - AssertEqual(CommonTags.CIProvider); - AssertEqual(CommonTags.CIPipelineId); - AssertEqual(CommonTags.CIPipelineName); - AssertEqual(CommonTags.CIPipelineNumber); - AssertEqual(CommonTags.CIPipelineUrl); - AssertEqual(CommonTags.CIJobUrl); - AssertEqual(CommonTags.CIJobName); - AssertEqual(CommonTags.StageName); - AssertEqual(CommonTags.CIWorkspacePath); - AssertEqual(CommonTags.GitRepository); - AssertEqual(CommonTags.GitCommit); - AssertEqual(CommonTags.GitBranch); - AssertEqual(CommonTags.GitTag); - AssertEqual(CommonTags.GitCommitAuthorName); - AssertEqual(CommonTags.GitCommitAuthorEmail); - AssertEqual(CommonTags.GitCommitAuthorDate); - AssertEqual(CommonTags.GitCommitCommitterName); - AssertEqual(CommonTags.GitCommitCommitterEmail); - AssertEqual(CommonTags.GitCommitCommitterDate); - AssertEqual(CommonTags.GitCommitMessage); - AssertEqual(CommonTags.BuildSourceRoot); - - void AssertEqual(string key) - { - if (span.GetTag(key) is not null) - { - Assert.Equal(span.GetTag(key), targetSpan.Tags[key]); - targetSpan.Tags.Remove(key); - } - } - } - - private static void CheckRuntimeValues(MockSpan targetSpan) - { - FrameworkDescription framework = FrameworkDescription.Instance; - - AssertTargetSpanEqual(targetSpan, CommonTags.RuntimeName, framework.Name); - AssertTargetSpanEqual(targetSpan, CommonTags.RuntimeVersion, framework.ProductVersion); - AssertTargetSpanEqual(targetSpan, CommonTags.RuntimeArchitecture, framework.ProcessArchitecture); - AssertTargetSpanEqual(targetSpan, CommonTags.OSArchitecture, framework.OSArchitecture); - AssertTargetSpanEqual(targetSpan, CommonTags.OSPlatform, framework.OSPlatform); - AssertTargetSpanEqual(targetSpan, CommonTags.OSVersion, Environment.OSVersion.VersionString); - } - - private static void CheckTraitsValues(MockSpan targetSpan) - { - // Check the traits tag value - AssertTargetSpanEqual(targetSpan, TestTags.Traits, "{\"Category\":[\"Category01\"],\"Compatibility\":[\"Windows\",\"Linux\"]}"); - } - - private static void CheckOriginTag(MockSpan targetSpan) - { - // Check the test origin tag - AssertTargetSpanEqual(targetSpan, Tags.Origin, TestTags.CIAppTestOriginName); - } - - private static void CheckSimpleTestSpan(MockSpan targetSpan) - { - // Check the Test Status - AssertTargetSpanEqual(targetSpan, TestTags.Status, TestTags.StatusPass); - } - - private static void CheckSimpleSkipFromAttributeTest(MockSpan targetSpan) - { - // Check the Test Status - AssertTargetSpanEqual(targetSpan, TestTags.Status, TestTags.StatusSkip); - - // Check the Test skip reason - AssertTargetSpanEqual(targetSpan, TestTags.SkipReason, "Simple skip reason"); - } - - private static void CheckSimpleErrorTest(MockSpan targetSpan) - { - // Check the Test Status - AssertTargetSpanEqual(targetSpan, TestTags.Status, TestTags.StatusFail); - - // Check the span error flag - Assert.Equal(1, targetSpan.Error); - - // Check the error type - AssertTargetSpanEqual(targetSpan, Tags.ErrorType, typeof(DivideByZeroException).FullName); - - // Check the error stack - AssertTargetSpanContains(targetSpan, Tags.ErrorStack, typeof(DivideByZeroException).FullName); - - // Check the error message - AssertTargetSpanEqual(targetSpan, Tags.ErrorMsg, new DivideByZeroException().Message); - } - } -} diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CI/NUnitTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CI/NUnitTests.cs deleted file mode 100644 index db14019fb..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CI/NUnitTests.cs +++ /dev/null @@ -1,374 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Datadog.Trace.Ci; -using Datadog.Trace.Ci.Tags; -using Datadog.Trace.ExtensionMethods; -using Datadog.Trace.TestHelpers; -using Xunit; -using Xunit.Abstractions; - -namespace Datadog.Trace.ClrProfiler.IntegrationTests.CI -{ - public class NUnitTests : TestHelper - { - private const int ExpectedSpanCount = 20; - - private const string TestBundleName = "Samples.NUnitTests"; - private static string[] _testSuiteNames = new string[] - { - "Samples.NUnitTests.TestSuite", - "Samples.NUnitTests.TestFixtureTest(\"Test01\")", - "Samples.NUnitTests.TestFixtureTest(\"Test02\")", - "Samples.NUnitTests.TestString", - }; - - public NUnitTests(ITestOutputHelper output) - : base("NUnitTests", output) - { - SetServiceVersion("1.0.0"); - } - - [SkippableTheory] - [MemberData(nameof(PackageVersions.NUnit), MemberType = typeof(PackageVersions))] - [Trait("Category", "EndToEnd")] - [Trait("Category", "TestIntegrations")] - public void SubmitTraces(string packageVersion) - { - if (new Version(FrameworkDescription.Instance.ProductVersion).Major >= 5) - { - if (!string.IsNullOrWhiteSpace(packageVersion) && new Version(packageVersion) < new Version("3.13")) - { - // Ignore due https://github.com/nunit/nunit/issues/3565#issuecomment-726835235 - return; - } - } - - List spans = null; - try - { - SetEnvironmentVariable("SIGNALFX_CIVISIBILITY_ENABLED", "1"); - SetEnvironmentVariable("SIGNALFX_TRACE_DEBUG", "1"); - SetEnvironmentVariable("SIGNALFX_DUMP_ILREWRITE_ENABLED", "1"); - - using (var agent = EnvironmentHelper.GetMockAgent()) - using (ProcessResult processResult = RunDotnetTestSampleAndWaitForExit(agent, packageVersion: packageVersion)) - { - spans = agent.WaitForSpans(ExpectedSpanCount) - .Where(s => !(s.Tags.TryGetValue(Tags.InstrumentationName, out var sValue) && sValue == "HttpMessageHandler")) - .ToList(); - - // Check the span count - Assert.Equal(ExpectedSpanCount, spans.Count); - - foreach (var targetSpan in spans) - { - // check the name - Assert.Equal("nunit.test", targetSpan.Name); - - // check the CIEnvironmentValues decoration. - CheckCIEnvironmentValuesDecoration(targetSpan); - - // check the runtime values - CheckRuntimeValues(targetSpan); - - // check the bundle name - AssertTargetSpanAnyOf(targetSpan, TestTags.Bundle, TestBundleName); - - // check the suite name - AssertTargetSpanAnyOf(targetSpan, TestTags.Suite, _testSuiteNames); - - // check the test type - AssertTargetSpanEqual(targetSpan, TestTags.Type, TestTags.TypeTest); - - // check the test framework - AssertTargetSpanContains(targetSpan, TestTags.Framework, "NUnit"); - Assert.True(targetSpan.Tags.Remove(TestTags.FrameworkVersion)); - - // check the version - AssertTargetSpanEqual(targetSpan, "version", "1.0.0"); - - // check the SignalFx library name - AssertTargetSpanEqual(targetSpan, "signalfx.tracing.library", "dotnet-tracing"); - - // check the SignalFx library version - AssertTargetSpanEqual(targetSpan, "signalfx.tracing.version", "1.1.0.0"); - - // checks the runtime id tag - AssertTargetSpanExists(targetSpan, Tags.RuntimeId); - - // checks the source tags - AssertTargetSpanExists(targetSpan, TestTags.SourceFile); - - // checks code owners - AssertTargetSpanExists(targetSpan, TestTags.CodeOwners); - - // checks the origin tag - CheckOriginTag(targetSpan); - - // Check the Environment - AssertTargetSpanEqual(targetSpan, Tags.Env, "integration_tests"); - - // Language - AssertTargetSpanEqual(targetSpan, Tags.Language, TracerConstants.Language); - - // CI Library Language - AssertTargetSpanEqual(targetSpan, CommonTags.LibraryVersion, TracerConstants.AssemblyVersion); - - // check specific test span - switch (targetSpan.Tags[TestTags.Name]) - { - case "SimplePassTest": - case "Test": - case "IsNull": - CheckSimpleTestSpan(targetSpan); - break; - - case "SimpleSkipFromAttributeTest": - CheckSimpleSkipFromAttributeTest(targetSpan); - break; - - case "SimpleErrorTest": - CheckSimpleErrorTest(targetSpan); - break; - - case "TraitPassTest": - CheckSimpleTestSpan(targetSpan); - CheckTraitsValues(targetSpan); - break; - - case "TraitSkipFromAttributeTest": - CheckSimpleSkipFromAttributeTest(targetSpan); - CheckTraitsValues(targetSpan); - break; - - case "TraitErrorTest": - CheckSimpleErrorTest(targetSpan); - CheckTraitsValues(targetSpan); - break; - - case "SimpleParameterizedTest": - CheckSimpleTestSpan(targetSpan); - AssertTargetSpanAnyOf( - targetSpan, - TestTags.Parameters, - "{\"metadata\":{\"test_name\":\"SimpleParameterizedTest(1,1,2)\"},\"arguments\":{\"xValue\":\"1\",\"yValue\":\"1\",\"expectedResult\":\"2\"}}", - "{\"metadata\":{\"test_name\":\"SimpleParameterizedTest(2,2,4)\"},\"arguments\":{\"xValue\":\"2\",\"yValue\":\"2\",\"expectedResult\":\"4\"}}", - "{\"metadata\":{\"test_name\":\"SimpleParameterizedTest(3,3,6)\"},\"arguments\":{\"xValue\":\"3\",\"yValue\":\"3\",\"expectedResult\":\"6\"}}"); - break; - - case "SimpleSkipParameterizedTest": - CheckSimpleSkipFromAttributeTest(targetSpan); - AssertTargetSpanAnyOf( - targetSpan, - TestTags.Parameters, - "{\"metadata\":{\"test_name\":\"SimpleSkipParameterizedTest(1,1,2)\"},\"arguments\":{\"xValue\":\"1\",\"yValue\":\"1\",\"expectedResult\":\"2\"}}", - "{\"metadata\":{\"test_name\":\"SimpleSkipParameterizedTest(2,2,4)\"},\"arguments\":{\"xValue\":\"2\",\"yValue\":\"2\",\"expectedResult\":\"4\"}}", - "{\"metadata\":{\"test_name\":\"SimpleSkipParameterizedTest(3,3,6)\"},\"arguments\":{\"xValue\":\"3\",\"yValue\":\"3\",\"expectedResult\":\"6\"}}"); - break; - - case "SimpleErrorParameterizedTest": - CheckSimpleErrorTest(targetSpan); - AssertTargetSpanAnyOf( - targetSpan, - TestTags.Parameters, - "{\"metadata\":{\"test_name\":\"SimpleErrorParameterizedTest(1,0,2)\"},\"arguments\":{\"xValue\":\"1\",\"yValue\":\"0\",\"expectedResult\":\"2\"}}", - "{\"metadata\":{\"test_name\":\"SimpleErrorParameterizedTest(2,0,4)\"},\"arguments\":{\"xValue\":\"2\",\"yValue\":\"0\",\"expectedResult\":\"4\"}}", - "{\"metadata\":{\"test_name\":\"SimpleErrorParameterizedTest(3,0,6)\"},\"arguments\":{\"xValue\":\"3\",\"yValue\":\"0\",\"expectedResult\":\"6\"}}"); - break; - - case "SimpleAssertPassTest": - CheckSimpleTestSpan(targetSpan); - break; - - case "SimpleAssertInconclusive": - CheckSimpleSkipFromAttributeTest(targetSpan, "The test is inconclusive."); - break; - } - - // check remaining tag (only the name) - Assert.Single(targetSpan.Tags); - } - } - } - catch - { - Console.WriteLine("Framework Version: " + new Version(FrameworkDescription.Instance.ProductVersion)); - if (!string.IsNullOrWhiteSpace(packageVersion)) - { - Console.WriteLine("Package Version: " + new Version(packageVersion)); - } - - WriteSpans(spans); - throw; - } - } - - private static void WriteSpans(List spans) - { - if (spans is null || spans.Count == 0) - { - return; - } - - Console.WriteLine("***********************************"); - - int i = 0; - foreach (var span in spans) - { - Console.Write($" {i++}) "); - Console.Write($"TraceId={span.TraceId}, "); - Console.Write($"SpanId={span.SpanId}, "); - Console.Write($"Service={span.Service}, "); - Console.Write($"Name={span.Name}, "); - Console.Write($"Resource={span.Resource}, "); - Console.Write($"Type={span.Type}, "); - Console.Write($"Error={span.Error}"); - Console.WriteLine(); - Console.WriteLine($" Tags="); - foreach (var kv in span.Tags) - { - Console.WriteLine($" => {kv.Key} = {kv.Value}"); - } - - Console.WriteLine(); - } - - Console.WriteLine("***********************************"); - } - - private static void AssertTargetSpanAnyOf(MockSpan targetSpan, string key, params string[] values) - { - string actualValue = targetSpan.Tags[key]; - Assert.Contains(actualValue, values); - targetSpan.Tags.Remove(key); - } - - private static void AssertTargetSpanEqual(MockSpan targetSpan, string key, string value) - { - Assert.Equal(value, targetSpan.Tags[key]); - targetSpan.Tags.Remove(key); - } - - private static void AssertTargetSpanExists(MockSpan targetSpan, string key) - { - Assert.True(targetSpan.Tags.ContainsKey(key)); - targetSpan.Tags.Remove(key); - } - - private static void AssertTargetSpanContains(MockSpan targetSpan, string key, string value) - { - Assert.Contains(value, targetSpan.Tags[key]); - targetSpan.Tags.Remove(key); - } - - private static void CheckCIEnvironmentValuesDecoration(MockSpan targetSpan) - { - var context = new SpanContext(null, null, null, null); - var span = new Span(context, DateTimeOffset.UtcNow); - CIEnvironmentValues.Instance.DecorateSpan(span); - - AssertEqual(CommonTags.CIProvider); - AssertEqual(CommonTags.CIPipelineId); - AssertEqual(CommonTags.CIPipelineName); - AssertEqual(CommonTags.CIPipelineNumber); - AssertEqual(CommonTags.CIPipelineUrl); - AssertEqual(CommonTags.CIJobUrl); - AssertEqual(CommonTags.CIJobName); - AssertEqual(CommonTags.StageName); - AssertEqual(CommonTags.CIWorkspacePath); - AssertEqual(CommonTags.GitRepository); - AssertEqual(CommonTags.GitCommit); - AssertEqual(CommonTags.GitBranch); - AssertEqual(CommonTags.GitTag); - AssertEqual(CommonTags.GitCommitAuthorName); - AssertEqual(CommonTags.GitCommitAuthorEmail); - AssertEqual(CommonTags.GitCommitAuthorDate); - AssertEqual(CommonTags.GitCommitCommitterName); - AssertEqual(CommonTags.GitCommitCommitterEmail); - AssertEqual(CommonTags.GitCommitCommitterDate); - AssertEqual(CommonTags.GitCommitMessage); - AssertEqual(CommonTags.BuildSourceRoot); - - void AssertEqual(string key) - { - if (span.GetTag(key) is not null) - { - Assert.Equal(span.GetTag(key), targetSpan.Tags[key]); - targetSpan.Tags.Remove(key); - } - } - } - - private static void CheckRuntimeValues(MockSpan targetSpan) - { - FrameworkDescription framework = FrameworkDescription.Instance; - - AssertTargetSpanEqual(targetSpan, CommonTags.RuntimeName, framework.Name); - AssertTargetSpanEqual(targetSpan, CommonTags.RuntimeVersion, framework.ProductVersion); - AssertTargetSpanEqual(targetSpan, CommonTags.RuntimeArchitecture, framework.ProcessArchitecture); - AssertTargetSpanEqual(targetSpan, CommonTags.OSArchitecture, framework.OSArchitecture); - AssertTargetSpanEqual(targetSpan, CommonTags.OSPlatform, framework.OSPlatform); - AssertTargetSpanEqual(targetSpan, CommonTags.OSVersion, Environment.OSVersion.VersionString); - } - - private static void CheckTraitsValues(MockSpan targetSpan) - { - // Check the traits tag value - AssertTargetSpanEqual(targetSpan, TestTags.Traits, "{\"Category\":[\"Category01\"],\"Compatibility\":[\"Windows\",\"Linux\"]}"); - } - - private static void CheckOriginTag(MockSpan targetSpan) - { - // Check the test origin tag - AssertTargetSpanEqual(targetSpan, Tags.Origin, TestTags.CIAppTestOriginName); - } - - private static void CheckSimpleTestSpan(MockSpan targetSpan) - { - // Check the Test Status - AssertTargetSpanEqual(targetSpan, TestTags.Status, TestTags.StatusPass); - - // Check the `test.message` tag. We check if contains the default or the custom message. - if (targetSpan.Tags.ContainsKey(TestTags.Message)) - { - AssertTargetSpanAnyOf(targetSpan, TestTags.Message, new string[] { "Test is ok", "The test passed." }); - } - } - - private static void CheckSimpleSkipFromAttributeTest(MockSpan targetSpan, string skipReason = "Simple skip reason") - { - // Check the Test Status - AssertTargetSpanEqual(targetSpan, TestTags.Status, TestTags.StatusSkip); - - // Check the Test skip reason - AssertTargetSpanEqual(targetSpan, TestTags.SkipReason, skipReason); - } - - private static void CheckSimpleErrorTest(MockSpan targetSpan) - { - // Check the Test Status - AssertTargetSpanEqual(targetSpan, TestTags.Status, TestTags.StatusFail); - - // Check the span error flag - Assert.Equal(1, targetSpan.Error); - - // Check the error type - AssertTargetSpanEqual(targetSpan, Tags.ErrorType, typeof(DivideByZeroException).FullName); - - // Check the error stack - AssertTargetSpanContains(targetSpan, Tags.ErrorStack, typeof(DivideByZeroException).FullName); - - // Check the error message - AssertTargetSpanEqual(targetSpan, Tags.ErrorMsg, new DivideByZeroException().Message); - } - } -} diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CI/XUnitTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CI/XUnitTests.cs deleted file mode 100644 index 432a2da56..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CI/XUnitTests.cs +++ /dev/null @@ -1,356 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading; -using Datadog.Trace.Ci; -using Datadog.Trace.Ci.Tags; -using Datadog.Trace.Configuration; -using Datadog.Trace.ExtensionMethods; -using Datadog.Trace.TestHelpers; -using Xunit; -using Xunit.Abstractions; - -namespace Datadog.Trace.ClrProfiler.IntegrationTests.CI -{ - public class XUnitTests : TestHelper - { - private const string TestBundleName = "Samples.XUnitTests"; - private const string TestSuiteName = "Samples.XUnitTests.TestSuite"; - private const int ExpectedSpanCount = 13; - - public XUnitTests(ITestOutputHelper output) - : base("XUnitTests", output) - { - SetServiceVersion("1.0.0"); - } - - [SkippableTheory] - [MemberData(nameof(PackageVersions.XUnit), MemberType = typeof(PackageVersions))] - [Trait("Category", "EndToEnd")] - [Trait("Category", "TestIntegrations")] - public void SubmitTraces(string packageVersion) - { - List spans = null; - string[] messages = null; - try - { - SetEnvironmentVariable("SIGNALFX_CIVISIBILITY_ENABLED", "1"); - SetEnvironmentVariable("SIGNALFX_TRACE_DEBUG", "1"); - SetEnvironmentVariable("SIGNALFX_DUMP_ILREWRITE_ENABLED", "1"); - - using var logsIntake = new MockLogsIntake(); - EnableDirectLogSubmission(logsIntake.Port, nameof(IntegrationId.XUnit), nameof(XUnitTests)); - SetEnvironmentVariable(ConfigurationKeys.CIVisibility.Logs, "1"); - - using (var agent = EnvironmentHelper.GetMockAgent()) - using (ProcessResult processResult = RunDotnetTestSampleAndWaitForExit(agent, packageVersion: packageVersion)) - { - spans = agent.WaitForSpans(ExpectedSpanCount) - .Where(s => !(s.Tags.TryGetValue(Tags.InstrumentationName, out var sValue) && sValue == "HttpMessageHandler")) - .ToList(); - - // Check the span count - Assert.Equal(ExpectedSpanCount, spans.Count); - - // *************************************************************************** - - foreach (var targetSpan in spans) - { - // check the name - Assert.Equal("xunit.test", targetSpan.Name); - - // check the CIEnvironmentValues decoration. - CheckCIEnvironmentValuesDecoration(targetSpan); - - // check the runtime values - CheckRuntimeValues(targetSpan); - - // check the bundle name - AssertTargetSpanEqual(targetSpan, TestTags.Bundle, TestBundleName); - - // check the suite name - AssertTargetSpanEqual(targetSpan, TestTags.Suite, TestSuiteName); - - // check the test type - AssertTargetSpanEqual(targetSpan, TestTags.Type, TestTags.TypeTest); - - // check the test framework - AssertTargetSpanContains(targetSpan, TestTags.Framework, "xUnit"); - Assert.True(targetSpan.Tags.Remove(TestTags.FrameworkVersion)); - - // check the version - AssertTargetSpanEqual(targetSpan, "version", "1.0.0"); - - // check the SignalFx library name - AssertTargetSpanEqual(targetSpan, "signalfx.tracing.library", "dotnet-tracing"); - - // check the SignalFx library version - AssertTargetSpanEqual(targetSpan, "signalfx.tracing.version", "1.1.0.0"); - - // checks the origin tag - CheckOriginTag(targetSpan); - - // checks the runtime id tag - AssertTargetSpanExists(targetSpan, Tags.RuntimeId); - - // checks the source tags - AssertTargetSpanExists(targetSpan, TestTags.SourceFile); - - // checks code owners - AssertTargetSpanExists(targetSpan, TestTags.CodeOwners); - - // Check the Environment - AssertTargetSpanEqual(targetSpan, Tags.Env, "integration_tests"); - - // Language - AssertTargetSpanEqual(targetSpan, Tags.Language, TracerConstants.Language); - - // CI Library Language - AssertTargetSpanEqual(targetSpan, CommonTags.LibraryVersion, TracerConstants.AssemblyVersion); - - // check specific test span - switch (targetSpan.Tags[TestTags.Name]) - { - case "SimplePassTest": - CheckSimpleTestSpan(targetSpan); - break; - - case "SimpleSkipFromAttributeTest": - CheckSimpleSkipFromAttributeTest(targetSpan); - break; - - case "SimpleErrorTest": - CheckSimpleErrorTest(targetSpan); - break; - - case "TraitPassTest": - CheckSimpleTestSpan(targetSpan); - CheckTraitsValues(targetSpan); - break; - - case "TraitSkipFromAttributeTest": - CheckSimpleSkipFromAttributeTest(targetSpan); - CheckTraitsValues(targetSpan); - break; - - case "TraitErrorTest": - CheckSimpleErrorTest(targetSpan); - CheckTraitsValues(targetSpan); - break; - - case "SimpleParameterizedTest": - CheckSimpleTestSpan(targetSpan); - AssertTargetSpanAnyOf( - targetSpan, - TestTags.Parameters, - "{\"metadata\":{\"test_name\":\"Samples.XUnitTests.TestSuite.SimpleParameterizedTest(xValue: 1, yValue: 1, expectedResult: 2)\"},\"arguments\":{\"xValue\":\"1\",\"yValue\":\"1\",\"expectedResult\":\"2\"}}", - "{\"metadata\":{\"test_name\":\"Samples.XUnitTests.TestSuite.SimpleParameterizedTest(xValue: 2, yValue: 2, expectedResult: 4)\"},\"arguments\":{\"xValue\":\"2\",\"yValue\":\"2\",\"expectedResult\":\"4\"}}", - "{\"metadata\":{\"test_name\":\"Samples.XUnitTests.TestSuite.SimpleParameterizedTest(xValue: 3, yValue: 3, expectedResult: 6)\"},\"arguments\":{\"xValue\":\"3\",\"yValue\":\"3\",\"expectedResult\":\"6\"}}", - "{\"metadata\":{\"test_name\":\"SimpleParameterizedTest(xValue: 1, yValue: 1, expectedResult: 2)\"},\"arguments\":{\"xValue\":\"1\",\"yValue\":\"1\",\"expectedResult\":\"2\"}}", - "{\"metadata\":{\"test_name\":\"SimpleParameterizedTest(xValue: 2, yValue: 2, expectedResult: 4)\"},\"arguments\":{\"xValue\":\"2\",\"yValue\":\"2\",\"expectedResult\":\"4\"}}", - "{\"metadata\":{\"test_name\":\"SimpleParameterizedTest(xValue: 3, yValue: 3, expectedResult: 6)\"},\"arguments\":{\"xValue\":\"3\",\"yValue\":\"3\",\"expectedResult\":\"6\"}}"); - break; - - case "SimpleSkipParameterizedTest": - CheckSimpleSkipFromAttributeTest(targetSpan); - break; - - case "SimpleErrorParameterizedTest": - CheckSimpleErrorTest(targetSpan); - AssertTargetSpanAnyOf( - targetSpan, - TestTags.Parameters, - "{\"metadata\":{\"test_name\":\"Samples.XUnitTests.TestSuite.SimpleErrorParameterizedTest(xValue: 1, yValue: 0, expectedResult: 2)\"},\"arguments\":{\"xValue\":\"1\",\"yValue\":\"0\",\"expectedResult\":\"2\"}}", - "{\"metadata\":{\"test_name\":\"Samples.XUnitTests.TestSuite.SimpleErrorParameterizedTest(xValue: 2, yValue: 0, expectedResult: 4)\"},\"arguments\":{\"xValue\":\"2\",\"yValue\":\"0\",\"expectedResult\":\"4\"}}", - "{\"metadata\":{\"test_name\":\"Samples.XUnitTests.TestSuite.SimpleErrorParameterizedTest(xValue: 3, yValue: 0, expectedResult: 6)\"},\"arguments\":{\"xValue\":\"3\",\"yValue\":\"0\",\"expectedResult\":\"6\"}}", - "{\"metadata\":{\"test_name\":\"SimpleErrorParameterizedTest(xValue: 1, yValue: 0, expectedResult: 2)\"},\"arguments\":{\"xValue\":\"1\",\"yValue\":\"0\",\"expectedResult\":\"2\"}}", - "{\"metadata\":{\"test_name\":\"SimpleErrorParameterizedTest(xValue: 2, yValue: 0, expectedResult: 4)\"},\"arguments\":{\"xValue\":\"2\",\"yValue\":\"0\",\"expectedResult\":\"4\"}}", - "{\"metadata\":{\"test_name\":\"SimpleErrorParameterizedTest(xValue: 3, yValue: 0, expectedResult: 6)\"},\"arguments\":{\"xValue\":\"3\",\"yValue\":\"0\",\"expectedResult\":\"6\"}}"); - break; - } - - // check remaining tag (only the name) - Assert.Single(targetSpan.Tags); - } - - // *************************************************************************** - // Check logs - messages = logsIntake.Logs.Select(i => i.Message).Where(m => m.StartsWith("Test:")).ToArray(); - - Assert.Contains(messages, m => m.StartsWith("Test:SimplePassTest")); - Assert.Contains(messages, m => m.StartsWith("Test:SimpleErrorTest")); - Assert.Contains(messages, m => m.StartsWith("Test:TraitPassTest")); - Assert.Contains(messages, m => m.StartsWith("Test:TraitErrorTest")); - Assert.Contains(messages, m => m.StartsWith("Test:SimpleParameterizedTest")); - Assert.Contains(messages, m => m.StartsWith("Test:SimpleErrorParameterizedTest")); - } - } - catch - { - WriteSpans(spans); - throw; - } - } - - private static void WriteSpans(List spans) - { - if (spans is null || spans.Count == 0) - { - return; - } - - Console.WriteLine("***********************************"); - - int i = 0; - foreach (var span in spans) - { - Console.Write($" {i++}) "); - Console.Write($"TraceId={span.TraceId}, "); - Console.Write($"SpanId={span.SpanId}, "); - Console.Write($"Service={span.Service}, "); - Console.Write($"Name={span.Name}, "); - Console.Write($"Resource={span.Resource}, "); - Console.Write($"Type={span.Type}, "); - Console.Write($"Error={span.Error}"); - Console.WriteLine(); - Console.WriteLine($" Tags="); - foreach (var kv in span.Tags) - { - Console.WriteLine($" => {kv.Key} = {kv.Value}"); - } - - Console.WriteLine(); - } - - Console.WriteLine("***********************************"); - } - - private static void AssertTargetSpanAnyOf(MockSpan targetSpan, string key, params string[] values) - { - string actualValue = targetSpan.Tags[key]; - Assert.Contains(actualValue, values); - targetSpan.Tags.Remove(key); - } - - private static void AssertTargetSpanEqual(MockSpan targetSpan, string key, string value) - { - Assert.Equal(value, targetSpan.Tags[key]); - targetSpan.Tags.Remove(key); - } - - private static void AssertTargetSpanExists(MockSpan targetSpan, string key) - { - Assert.True(targetSpan.Tags.ContainsKey(key)); - targetSpan.Tags.Remove(key); - } - - private static void AssertTargetSpanContains(MockSpan targetSpan, string key, string value) - { - Assert.Contains(value, targetSpan.Tags[key]); - targetSpan.Tags.Remove(key); - } - - private static void CheckCIEnvironmentValuesDecoration(MockSpan targetSpan) - { - var context = new SpanContext(null, null, null, null); - var span = new Span(context, DateTimeOffset.UtcNow); - CIEnvironmentValues.Instance.DecorateSpan(span); - - AssertEqual(CommonTags.CIProvider); - AssertEqual(CommonTags.CIPipelineId); - AssertEqual(CommonTags.CIPipelineName); - AssertEqual(CommonTags.CIPipelineNumber); - AssertEqual(CommonTags.CIPipelineUrl); - AssertEqual(CommonTags.CIJobUrl); - AssertEqual(CommonTags.CIJobName); - AssertEqual(CommonTags.StageName); - AssertEqual(CommonTags.CIWorkspacePath); - AssertEqual(CommonTags.GitRepository); - AssertEqual(CommonTags.GitCommit); - AssertEqual(CommonTags.GitBranch); - AssertEqual(CommonTags.GitTag); - AssertEqual(CommonTags.GitCommitAuthorName); - AssertEqual(CommonTags.GitCommitAuthorEmail); - AssertEqual(CommonTags.GitCommitAuthorDate); - AssertEqual(CommonTags.GitCommitCommitterName); - AssertEqual(CommonTags.GitCommitCommitterEmail); - AssertEqual(CommonTags.GitCommitCommitterDate); - AssertEqual(CommonTags.GitCommitMessage); - AssertEqual(CommonTags.BuildSourceRoot); - - void AssertEqual(string key) - { - if (span.GetTag(key) is not null) - { - Assert.Equal(span.GetTag(key), targetSpan.Tags[key]); - targetSpan.Tags.Remove(key); - } - } - } - - private static void CheckRuntimeValues(MockSpan targetSpan) - { - FrameworkDescription framework = FrameworkDescription.Instance; - - AssertTargetSpanEqual(targetSpan, CommonTags.RuntimeName, framework.Name); - AssertTargetSpanEqual(targetSpan, CommonTags.RuntimeVersion, framework.ProductVersion); - AssertTargetSpanEqual(targetSpan, CommonTags.RuntimeArchitecture, framework.ProcessArchitecture); - AssertTargetSpanEqual(targetSpan, CommonTags.OSArchitecture, framework.OSArchitecture); - AssertTargetSpanEqual(targetSpan, CommonTags.OSPlatform, framework.OSPlatform); - AssertTargetSpanEqual(targetSpan, CommonTags.OSVersion, Environment.OSVersion.VersionString); - } - - private static void CheckTraitsValues(MockSpan targetSpan) - { - // Check the traits tag value - AssertTargetSpanEqual(targetSpan, TestTags.Traits, "{\"Category\":[\"Category01\"],\"Compatibility\":[\"Windows\",\"Linux\"]}"); - } - - private static void CheckOriginTag(MockSpan targetSpan) - { - // Check the test origin tag - AssertTargetSpanEqual(targetSpan, Tags.Origin, TestTags.CIAppTestOriginName); - } - - private static void CheckSimpleTestSpan(MockSpan targetSpan) - { - // Check the Test Status - AssertTargetSpanEqual(targetSpan, TestTags.Status, TestTags.StatusPass); - } - - private static void CheckSimpleSkipFromAttributeTest(MockSpan targetSpan) - { - // Check the Test Status - AssertTargetSpanEqual(targetSpan, TestTags.Status, TestTags.StatusSkip); - - // Check the Test skip reason - AssertTargetSpanEqual(targetSpan, TestTags.SkipReason, "Simple skip reason"); - } - - private static void CheckSimpleErrorTest(MockSpan targetSpan) - { - // Check the Test Status - AssertTargetSpanEqual(targetSpan, TestTags.Status, TestTags.StatusFail); - - // Check the span error flag - Assert.Equal(1, targetSpan.Error); - - // Check the error type - AssertTargetSpanEqual(targetSpan, Tags.ErrorType, typeof(DivideByZeroException).FullName); - - // Check the error stack - AssertTargetSpanContains(targetSpan, Tags.ErrorStack, typeof(DivideByZeroException).FullName); - - // Check the error message - AssertTargetSpanEqual(targetSpan, Tags.ErrorMsg, new DivideByZeroException().Message); - } - } -} diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CosmosTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CosmosTests.cs index 81c853a89..f9904fb71 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CosmosTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CosmosTests.cs @@ -44,7 +44,6 @@ public void SubmitsTraces(string packageVersion) { var expectedSpanCount = 14; - using var telemetry = this.ConfigureTelemetry(); using (var agent = EnvironmentHelper.GetMockAgent()) using (RunSampleAndWaitForExit(agent, arguments: $"{TestPrefix}", packageVersion: packageVersion)) { @@ -84,7 +83,6 @@ public void SubmitsTraces(string packageVersion) dbTags.Should().Be(10); containerTags.Should().Be(4); - telemetry.AssertIntegrationEnabled(IntegrationId.CosmosDb); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Couchbase3Tests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Couchbase3Tests.cs index 63535ce84..b5289f50b 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Couchbase3Tests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Couchbase3Tests.cs @@ -38,7 +38,6 @@ public static System.Collections.Generic.IEnumerable GetCouchbase() [Trait("Category", "ArmUnsupported")] public void SubmitTraces(string packageVersion) { - using var telemetry = this.ConfigureTelemetry(); using (var agent = EnvironmentHelper.GetMockAgent()) using (RunSampleAndWaitForExit(agent, packageVersion: packageVersion)) { @@ -69,7 +68,6 @@ public void SubmitTraces(string packageVersion) } ValidateSpans(spans, (span) => span.Resource, expected); - telemetry.AssertIntegrationEnabled(IntegrationId.Couchbase); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CouchbaseTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CouchbaseTests.cs index c48d27d0d..b5c29f12a 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CouchbaseTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/CouchbaseTests.cs @@ -38,7 +38,6 @@ public static System.Collections.Generic.IEnumerable GetCouchbase() [Trait("Category", "ArmUnsupported")] public void SubmitTraces(string packageVersion) { - using var telemetry = this.ConfigureTelemetry(); using (var agent = EnvironmentHelper.GetMockAgent()) using (RunSampleAndWaitForExit(agent, packageVersion: packageVersion)) { @@ -60,7 +59,6 @@ public void SubmitTraces(string packageVersion) }; ValidateSpans(spans, (span) => span.Resource, expected); - telemetry.AssertIntegrationEnabled(IntegrationId.Couchbase); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Elasticsearch5Tests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Elasticsearch5Tests.cs index 752da89dc..8b775fad1 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Elasticsearch5Tests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Elasticsearch5Tests.cs @@ -41,7 +41,6 @@ public void SubmitsTraces(string packageVersion, bool tagQueries) { SetEnvironmentVariable("SIGNALFX_INSTRUMENTATION_ELASTICSEARCH_TAG_QUERIES", tagQueries.ToString().ToLowerInvariant()); - using var telemetry = this.ConfigureTelemetry(); using (var agent = EnvironmentHelper.GetMockAgent()) using (RunSampleAndWaitForExit(agent, packageVersion: packageVersion)) { @@ -174,7 +173,6 @@ public void SubmitsTraces(string packageVersion, bool tagQueries) } ValidateSpans(spans, (span) => span.Resource, expected); - telemetry.AssertIntegrationEnabled(IntegrationId.ElasticsearchNet); } } @@ -183,7 +181,6 @@ public void SubmitsTraces(string packageVersion, bool tagQueries) [Trait("Category", "ArmUnsupported")] public void IntegrationDisabled() { - using var telemetry = this.ConfigureTelemetry(); string packageVersion = PackageVersions.ElasticSearch5.First()[0] as string; SetEnvironmentVariable($"SIGNALFX_TRACE_{nameof(IntegrationId.ElasticsearchNet)}_ENABLED", "false"); @@ -193,7 +190,6 @@ public void IntegrationDisabled() var spans = agent.WaitForSpans(1).Where(s => s.Type == "elasticsearch").ToList(); Assert.Empty(spans); - telemetry.AssertIntegrationDisabled(IntegrationId.ElasticsearchNet); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Elasticsearch6Tests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Elasticsearch6Tests.cs index 04126d1cc..ebedb3b93 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Elasticsearch6Tests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Elasticsearch6Tests.cs @@ -42,7 +42,6 @@ public void SubmitsTraces(string packageVersion, bool tagQueries) { SetEnvironmentVariable("SIGNALFX_INSTRUMENTATION_ELASTICSEARCH_TAG_QUERIES", tagQueries.ToString().ToLowerInvariant()); - using var telemetry = this.ConfigureTelemetry(); using (var agent = EnvironmentHelper.GetMockAgent()) using (RunSampleAndWaitForExit(agent, packageVersion: packageVersion)) { @@ -191,7 +190,6 @@ public void SubmitsTraces(string packageVersion, bool tagQueries) } ValidateSpans(spans, (span) => span.Resource, expected); - telemetry.AssertIntegrationEnabled(IntegrationId.ElasticsearchNet); } } @@ -200,7 +198,6 @@ public void SubmitsTraces(string packageVersion, bool tagQueries) [Trait("Category", "ArmUnsupported")] public void IntegrationDisabled() { - using var telemetry = this.ConfigureTelemetry(); string packageVersion = PackageVersions.ElasticSearch6.First()[0] as string; SetEnvironmentVariable($"SIGNALFX_TRACE_{nameof(IntegrationId.ElasticsearchNet)}_ENABLED", "false"); using var agent = EnvironmentHelper.GetMockAgent(); @@ -208,7 +205,6 @@ public void IntegrationDisabled() var spans = agent.WaitForSpans(1).Where(s => s.Type == "elasticsearch").ToList(); Assert.Empty(spans); - telemetry.AssertIntegrationDisabled(IntegrationId.ElasticsearchNet); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Elasticsearch7Tests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Elasticsearch7Tests.cs index d984b612d..8b4a8750d 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Elasticsearch7Tests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Elasticsearch7Tests.cs @@ -30,7 +30,6 @@ public Elasticsearch7Tests(ITestOutputHelper output) [Trait("Category", "EndToEnd")] public void SubmitsTraces(string packageVersion) { - using var telemetry = this.ConfigureTelemetry(); using (var agent = EnvironmentHelper.GetMockAgent()) using (RunSampleAndWaitForExit(agent, packageVersion: packageVersion)) { @@ -149,7 +148,6 @@ public void SubmitsTraces(string packageVersion) } ValidateSpans(spans, (span) => span.Resource, expected); - telemetry.AssertIntegrationEnabled(IntegrationId.ElasticsearchNet); } } @@ -158,7 +156,6 @@ public void SubmitsTraces(string packageVersion) [Trait("Category", "ArmUnsupported")] public void IntegrationDisabled() { - using var telemetry = this.ConfigureTelemetry(); string packageVersion = PackageVersions.ElasticSearch7.First()[0] as string; SetEnvironmentVariable($"SIGNALFX_TRACE_{nameof(IntegrationId.ElasticsearchNet)}_ENABLED", "false"); using var agent = EnvironmentHelper.GetMockAgent(); @@ -166,7 +163,6 @@ public void IntegrationDisabled() var spans = agent.WaitForSpans(1).Where(s => s.Type == "elasticsearch").ToList(); Assert.Empty(spans); - telemetry.AssertIntegrationDisabled(IntegrationId.ElasticsearchNet); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/GraphQLTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/GraphQLTests.cs index 7096621a2..37548c106 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/GraphQLTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/GraphQLTests.cs @@ -95,7 +95,6 @@ protected GraphQLTests(string sampleAppName, ITestOutputHelper output, string te protected async Task RunSubmitsTraces(string packageVersion = "") { SetInstrumentationVerification(); - using var telemetry = this.ConfigureTelemetry(); int? aspNetCorePort = null; using (var agent = EnvironmentHelper.GetMockAgent()) @@ -193,8 +192,6 @@ await VerifyHelper.VerifySpans(spans, settings) VerifyInstrumentation(process); } - - telemetry.AssertIntegrationEnabled(IntegrationId.GraphQL); } private int SubmitRequests(int aspNetCorePort) diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/GrpcTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/GrpcTests.cs index 3a6868fe5..2ec25df4f 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/GrpcTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/GrpcTests.cs @@ -261,7 +261,6 @@ protected async Task RunSubmitTraces( var totalExpectedSpans = (requestCount * spansPerRequest); - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using var assert = new AssertionScope(); using (var processResult = RunSampleAndWaitForExit(agent, packageVersion: packageVersion, aspNetCorePort: 0)) @@ -285,7 +284,6 @@ protected async Task RunSubmitTraces( if (!isGrpcSupported) { Output.WriteLine($"Package version {packageVersion} is not supported in Grpc, skipping snapshot verification"); - telemetry.AssertIntegrationDisabled(IntegrationId.Grpc); return; } @@ -394,20 +392,16 @@ static void FixVerySlowClientSpans(IImmutableList spans) } } } - - telemetry.AssertIntegrationEnabled(IntegrationId.Grpc); } protected void RunIntegrationDisabled(string packageVersion) { - using var telemetry = this.ConfigureTelemetry(); SetEnvironmentVariable($"SIGNALFX_TRACE_{nameof(IntegrationId.Grpc)}_ENABLED", "false"); using var agent = EnvironmentHelper.GetMockAgent(); using var process = RunSampleAndWaitForExit(agent, packageVersion: packageVersion, aspNetCorePort: 0); var spans = agent.WaitForSpans(1, timeoutInMilliseconds: 500).Where(s => s.Type == "grpc.request").ToList(); Assert.Empty(spans); - telemetry.AssertIntegrationDisabled(IntegrationId.Grpc); } protected void GuardAlpine() diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Helpers/TelemetryHelper.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Helpers/TelemetryHelper.cs deleted file mode 100644 index d06c4e6c0..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Helpers/TelemetryHelper.cs +++ /dev/null @@ -1,153 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System.Collections.Generic; -using System.Linq; -using Datadog.Trace.Configuration; -using Datadog.Trace.Telemetry; -using Datadog.Trace.TestHelpers; -using FluentAssertions; - -namespace Datadog.Trace.ClrProfiler.IntegrationTests -{ - internal static class TelemetryHelper - { - public static MockTelemetryAgent ConfigureTelemetry(this TestHelper helper) - { - int telemetryPort = TcpPortProvider.GetOpenPort(); - var telemetry = new MockTelemetryAgent(telemetryPort); - - helper.SetEnvironmentVariable("SIGNALFX_INSTRUMENTATION_TELEMETRY_ENABLED", "true"); - helper.SetEnvironmentVariable("SIGNALFX_INSTRUMENTATION_TELEMETRY_AGENTLESS_ENABLED", "true"); - helper.SetEnvironmentVariable("SIGNALFX_INSTRUMENTATION_TELEMETRY_URL", $"http://localhost:{telemetry.Port}"); - // removed, but necessary for some version conflict tests (e.g. TraceAnnotationsVersionMismatchNewerNuGetTests) - helper.SetEnvironmentVariable("SIGNALFX_TRACE_TELEMETRY_URL", $"http://localhost:{telemetry.Port}"); - // API key is required when using the custom url - helper.SetEnvironmentVariable("SIGNALFX_API_KEY", "INVALID_KEY_FOR_TESTS"); - return telemetry; - } - - public static TelemetryData AssertIntegrationEnabled(this MockTelemetryAgent telemetry, IntegrationId integrationId) - { - return telemetry.AssertIntegration(integrationId, enabled: true, autoEnabled: true); - } - - public static TelemetryData AssertIntegrationDisabled(this MockTelemetryAgent telemetry, IntegrationId integrationId) - { - return telemetry.AssertIntegration(integrationId, enabled: false, autoEnabled: true); - } - - public static TelemetryData AssertIntegrationEnabled(this MockTracerAgent mockAgent, IntegrationId integrationId) - { - return mockAgent.AssertIntegration(integrationId, enabled: true, autoEnabled: true); - } - - public static TelemetryData AssertIntegrationDisabled(this MockTracerAgent mockAgent, IntegrationId integrationId) - { - return mockAgent.AssertIntegration(integrationId, enabled: false, autoEnabled: true); - } - - public static TelemetryData AssertIntegration(this MockTracerAgent mockAgent, IntegrationId integrationId, bool enabled, bool? autoEnabled) - { - mockAgent.WaitForLatestTelemetry(x => ((TelemetryData)x).RequestType == TelemetryRequestTypes.AppClosing); - - var allData = mockAgent.Telemetry.Cast().ToArray(); - return AssertIntegration(allData, integrationId, enabled, autoEnabled); - } - - public static TelemetryData AssertIntegration(this MockTelemetryAgent telemetry, IntegrationId integrationId, bool enabled, bool? autoEnabled) - { - telemetry.WaitForLatestTelemetry(x => x.RequestType == TelemetryRequestTypes.AppClosing); - - var allData = telemetry.Telemetry.ToArray(); - return AssertIntegration(allData, integrationId, enabled, autoEnabled); - } - - public static TelemetryData AssertConfiguration(this MockTracerAgent mockAgent, string key) - { - mockAgent.WaitForLatestTelemetry(x => ((TelemetryData)x).RequestType == TelemetryRequestTypes.AppStarted); - - var allData = mockAgent.Telemetry.Cast().ToArray(); - return AssertConfiguration(allData, key); - } - - public static TelemetryData AssertConfiguration(this MockTelemetryAgent telemetry, string key, string value) - { - telemetry.WaitForLatestTelemetry(x => x.RequestType == TelemetryRequestTypes.AppStarted); - - var allData = telemetry.Telemetry.ToArray(); - return AssertConfiguration(allData, key, value); - } - - public static TelemetryData AssertConfiguration(this MockTelemetryAgent telemetry, string key) => telemetry.AssertConfiguration(key, value: null); - - private static TelemetryData AssertConfiguration(TelemetryData[] allData, string key, string value = null) - { - var (latestConfigurationData, configurationPayload) = - allData - .Where(x => x.RequestType == TelemetryRequestTypes.AppStarted) - .OrderByDescending(x => x.SeqId) - .Select( - data => - { - var configuration = ((AppStartedPayload)data.Payload).Configuration; - return (data, configuration); - }) - .FirstOrDefault(x => x.configuration is not null); - - latestConfigurationData.Should().NotBeNull(); - configurationPayload.Should().NotBeNull(); - - var config = configurationPayload.Should().ContainSingle(telemetryValue => telemetryValue.Name == key).Subject; - config.Should().NotBeNull(); - if (value is not null) - { - config.Value.Should().Be(value); - } - - return latestConfigurationData; - } - - private static TelemetryData AssertIntegration(TelemetryData[] allData, IntegrationId integrationId, bool enabled, bool? autoEnabled) - { - allData.Should().ContainSingle(x => x.RequestType == TelemetryRequestTypes.AppClosing); - - var (latestIntegrationsData, integrationsPayload) = - allData - .Where( - x => x.RequestType == TelemetryRequestTypes.AppStarted - || x.RequestType == TelemetryRequestTypes.AppIntegrationsChanged) - .OrderByDescending(x => x.SeqId) - .Select( - data => - { - var integrations = data.Payload is AppStartedPayload payload - ? payload.Integrations - : ((AppIntegrationsChangedPayload)data.Payload).Integrations; - return (data, integrations); - }) - .FirstOrDefault(x => x.integrations is not null); - - latestIntegrationsData.Should().NotBeNull(); - integrationsPayload.Should().NotBeNull(); - - var integration = integrationsPayload - .FirstOrDefault(x => x.Name == integrationId.ToString()); - - integration.Should().NotBeNull(); - integration.Enabled.Should().Be(enabled, $"{integration.Name} should only be enabled if we generate a span"); - if (autoEnabled.HasValue) - { - integration.AutoEnabled.Should().Be(autoEnabled.Value, $"{integration.Name} should only be auto-enabled if available"); - } - - integration.Error.Should().BeNullOrEmpty(); - - return latestIntegrationsData; - } - } -} diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/HttpMessageHandlerTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/HttpMessageHandlerTests.cs index 40fff54d4..6c2868310 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/HttpMessageHandlerTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/HttpMessageHandlerTests.cs @@ -64,7 +64,6 @@ public void HttpClient_SubmitsTraces(InstrumentationOptions instrumentation, boo int httpPort = TcpPortProvider.GetOpenPort(); Output.WriteLine($"Assigning port {httpPort} for the httpPort."); - using var telemetry = this.ConfigureTelemetry(); using (var agent = EnvironmentHelper.GetMockAgent()) using (ProcessResult processResult = RunSampleAndWaitForExit(agent, arguments: $"Port={httpPort}")) { @@ -86,11 +85,6 @@ public void HttpClient_SubmitsTraces(InstrumentationOptions instrumentation, boo PropagationTestHelpers.AssertPropagationEnabled(spans.First(), processResult); using var scope = new AssertionScope(); - telemetry.AssertIntegrationEnabled(IntegrationId.HttpMessageHandler); - // ignore for now auto enabled for simplicity - telemetry.AssertIntegration(IntegrationId.HttpSocketsHandler, enabled: IsUsingSocketHandler(instrumentation), autoEnabled: null); - telemetry.AssertIntegration(IntegrationId.WinHttpHandler, enabled: IsUsingWinHttpHandler(instrumentation), autoEnabled: null); - telemetry.AssertIntegration(IntegrationId.CurlHandler, enabled: IsUsingCurlHandler(instrumentation), autoEnabled: null); VerifyInstrumentation(processResult.Process); } } @@ -107,7 +101,6 @@ public void TracingDisabled_DoesNotSubmitsTraces(InstrumentationOptions instrume const string expectedOperationName = "http.request"; - using var telemetry = this.ConfigureTelemetry(); int httpPort = TcpPortProvider.GetOpenPort(); using (var agent = EnvironmentHelper.GetMockAgent()) @@ -120,10 +113,6 @@ public void TracingDisabled_DoesNotSubmitsTraces(InstrumentationOptions instrume using var scope = new AssertionScope(); // ignore auto enabled for simplicity - telemetry.AssertIntegrationDisabled(IntegrationId.HttpMessageHandler); - telemetry.AssertIntegration(IntegrationId.HttpSocketsHandler, enabled: false, autoEnabled: null); - telemetry.AssertIntegration(IntegrationId.WinHttpHandler, enabled: false, autoEnabled: null); - telemetry.AssertIntegration(IntegrationId.CurlHandler, enabled: false, autoEnabled: null); VerifyInstrumentation(processResult.Process); } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/ILoggerTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/ILoggerTests.cs index 8718d1ff8..a98e0740b 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/ILoggerTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/ILoggerTests.cs @@ -37,13 +37,11 @@ public ILoggerTests(ITestOutputHelper output) SetEnvironmentVariable("SIGNALFX_LOGS_INJECTION", "true"); } - [SkippableTheory] - [InlineData(false)] - [InlineData(true)] + [SkippableFact] [Trait("Category", "EndToEnd")] [Trait("RunOnWindows", "True")] [Trait("SupportsInstrumentationVerification", "True")] - public void InjectsLogs(bool enableLogShipping) + public void InjectsLogs() { // One of the traces starts by manual opening a span when the background service starts, // and then it sends a HTTP request to the server. @@ -61,11 +59,6 @@ public void InjectsLogs(bool enableLogShipping) #endif SetInstrumentationVerification(); - using var logsIntake = new MockLogsIntake(); - if (enableLogShipping) - { - EnableDirectLogSubmission(logsIntake.Port, nameof(IntegrationId.ILogger), nameof(InjectsLogs)); - } using (var agent = EnvironmentHelper.GetMockAgent()) using (var processResult = RunSampleAndWaitForExit(agent, aspNetCorePort: 0)) @@ -77,40 +70,5 @@ public void InjectsLogs(bool enableLogShipping) VerifyInstrumentation(processResult.Process); } } - - [SkippableFact] - [Trait("Category", "EndToEnd")] - [Trait("RunOnWindows", "True")] - [Trait("SupportsInstrumentationVerification", "True")] - public void DirectlyShipsLogs() - { - SetInstrumentationVerification(); - var hostName = "integration_ilogger_tests"; - using var logsIntake = new MockLogsIntake(); - - EnableDirectLogSubmission(logsIntake.Port, nameof(IntegrationId.ILogger), hostName); - - var agentPort = TcpPortProvider.GetOpenPort(); - using var agent = MockTracerAgent.Create(agentPort); - using var processResult = RunSampleAndWaitForExit(agent, aspNetCorePort: 0); - - Assert.True(processResult.ExitCode >= 0, $"Process exited with code {processResult.ExitCode} and exception: {processResult.StandardError}"); - - var logs = logsIntake.Logs; - - using var scope = new AssertionScope(); - logs.Should().NotBeNull(); - logs.Should().HaveCountGreaterOrEqualTo(12); // have an unknown number of "Waiting for app started handling requests" - logs.Should() - .OnlyContain(x => x.Service == "LogsInjection.ILogger") - .And.OnlyContain(x => x.Host == hostName) - .And.OnlyContain(x => x.Source == "csharp") - .And.OnlyContain(x => x.Env == "integration_tests") - .And.OnlyContain(x => x.Version == "1.0.0") - .And.OnlyContain(x => x.Exception == null) - .And.OnlyContain(x => x.LogLevel == DirectSubmissionLogLevel.Information); - - VerifyInstrumentation(processResult.Process); - } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/KafkaTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/KafkaTests.cs index cce26b6ac..602dcc4b2 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/KafkaTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/KafkaTests.cs @@ -51,7 +51,6 @@ public void SubmitsTraces(string packageVersion) { var topic = $"sample-topic-{TestPrefix}-{packageVersion}".Replace('.', '-'); - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using var processResult = RunSampleAndWaitForExit(agent, arguments: topic, packageVersion: packageVersion); @@ -141,8 +140,6 @@ public void SubmitsTraces(string packageVersion) .And.OnlyContain(x => x.Tags[Tags.ErrorMsg].Contains("Broker: Unknown topic or partition")) .And.OnlyContain(x => x.Tags[Tags.ErrorType] == "Confluent.Kafka.ConsumeException"); } - - telemetry.AssertIntegrationEnabled(IntegrationId.Kafka); } private void VerifyProducerSpanProperties(List producerSpans, string resourceName, int expectedCount) diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Log4NetTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Log4NetTests.cs index 18e18d4cb..8c914a4d2 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Log4NetTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Log4NetTests.cs @@ -57,9 +57,7 @@ public Log4NetTests(ITestOutputHelper output) public static System.Collections.Generic.IEnumerable GetTestData() { - return from item in PackageVersions.log4net - from logShipping in new[] { true, false } - select item.Concat(logShipping); + return PackageVersions.log4net; } [SkippableTheory] @@ -67,15 +65,10 @@ public static System.Collections.Generic.IEnumerable GetTestData() [Trait("Category", "EndToEnd")] [Trait("RunOnWindows", "True")] [Trait("SupportsInstrumentationVerification", "True")] - public void InjectsLogsWhenEnabled(string packageVersion, bool enableLogShipping) + public void InjectsLogsWhenEnabled(string packageVersion) { SetInstrumentationVerification(); SetEnvironmentVariable("SIGNALFX_LOGS_INJECTION", "true"); - using var logsIntake = new MockLogsIntake(); - if (enableLogShipping) - { - EnableDirectLogSubmission(logsIntake.Port, nameof(IntegrationId.Log4Net), nameof(InjectsLogsWhenEnabled)); - } var expectedCorrelatedTraceCount = 1; var expectedCorrelatedSpanCount = 1; @@ -108,15 +101,10 @@ public void InjectsLogsWhenEnabled(string packageVersion, bool enableLogShipping [Trait("Category", "EndToEnd")] [Trait("RunOnWindows", "True")] [Trait("SupportsInstrumentationVerification", "True")] - public void DoesNotInjectLogsWhenDisabled(string packageVersion, bool enableLogShipping) + public void DoesNotInjectLogsWhenDisabled(string packageVersion) { SetEnvironmentVariable("SIGNALFX_LOGS_INJECTION", "false"); SetInstrumentationVerification(); - using var logsIntake = new MockLogsIntake(); - if (enableLogShipping) - { - EnableDirectLogSubmission(logsIntake.Port, nameof(IntegrationId.Log4Net), nameof(DoesNotInjectLogsWhenDisabled)); - } var expectedCorrelatedTraceCount = 0; var expectedCorrelatedSpanCount = 0; @@ -144,53 +132,6 @@ public void DoesNotInjectLogsWhenDisabled(string packageVersion, bool enableLogS } } - [SkippableTheory] - [MemberData(nameof(PackageVersions.log4net), MemberType = typeof(PackageVersions))] - [Trait("Category", "EndToEnd")] - [Trait("RunOnWindows", "True")] - [Trait("SupportsInstrumentationVerification", "True")] - public void DirectlyShipsLogs(string packageVersion) - { - var hostName = "integration_log4net_tests"; - using var logsIntake = new MockLogsIntake(); - - SetInstrumentationVerification(); - SetEnvironmentVariable("SIGNALFX_LOGS_INJECTION", "true"); - EnableDirectLogSubmission(logsIntake.Port, nameof(IntegrationId.Log4Net), hostName); - - var agentPort = TcpPortProvider.GetOpenPort(); - using var agent = MockTracerAgent.Create(agentPort); - using var processResult = RunSampleAndWaitForExit(agent, packageVersion: packageVersion); - - Assert.True(processResult.ExitCode >= 0, $"Process exited with code {processResult.ExitCode} and exception: {processResult.StandardError}"); - - var logs = logsIntake.Logs; - - using var scope = new AssertionScope(); - logs.Should().NotBeNull(); - logs.Should().HaveCountGreaterOrEqualTo(3); - logs.Should() - .OnlyContain(x => x.Service == "LogsInjection.Log4Net") - .And.OnlyContain(x => x.Env == "integration_tests") - .And.OnlyContain(x => x.Version == "1.0.0") - .And.OnlyContain(x => x.Host == hostName) - .And.OnlyContain(x => x.Source == "csharp") - .And.OnlyContain(x => x.Exception == null) - .And.OnlyContain(x => x.LogLevel == DirectSubmissionLogLevel.Information); - - if (PackageSupportsLogsInjection(packageVersion)) - { - logs - .Where(x => !x.Message.Contains(ExcludeMessagePrefix)) - .Should() - .NotBeEmpty() - .And.OnlyContain(x => !string.IsNullOrEmpty(x.TraceId)) - .And.OnlyContain(x => !string.IsNullOrEmpty(x.SpanId)); - } - - VerifyInstrumentation(processResult.Process); - } - private static bool PackageSupportsLogsInjection(string packageVersion) => string.IsNullOrWhiteSpace(packageVersion) || new Version(packageVersion) >= new Version("2.0.0"); } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/MongoDbTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/MongoDbTests.cs index 65b3fc417..1056b2856 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/MongoDbTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/MongoDbTests.cs @@ -55,7 +55,6 @@ public async Task SubmitsTraces(string packageVersion, bool tagCommands) { SetEnvironmentVariable("SIGNALFX_INSTRUMENTATION_MONGODB_TAG_COMMANDS", tagCommands.ToString().ToLowerInvariant()); - using var telemetry = this.ConfigureTelemetry(); using (var agent = EnvironmentHelper.GetMockAgent()) using (RunSampleAndWaitForExit(agent, packageVersion: packageVersion)) { @@ -111,8 +110,6 @@ await VerifyHelper.VerifySpans(nonAdminSpans, settings) Assert.True(result.Success, result.ToString()); } - telemetry.AssertIntegrationEnabled(IntegrationId.MongoDb); - // do some basic verification on the "admin" spans using var scope = new AssertionScope(); adminSpans.Should().AllBeEquivalentTo(new { Service = "Samples.MongoDB", Type = "mongodb", }); diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/MsmqTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/MsmqTests.cs index 542e4cb57..71e92d62a 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/MsmqTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/MsmqTests.cs @@ -46,7 +46,6 @@ public void SubmitTraces() var transactionalTraces = 0; var nonTransactionalTraces = 0; - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using var processResult = RunSampleAndWaitForExit(agent, arguments: $"5 5"); @@ -110,7 +109,6 @@ public void SubmitTraces() purgeCount.Should().Be(expectedPurgeCount); receiveCount.Should().Be(expectedReceiveCount); peekCount.Should().Be(expectedPeekCount); - telemetry.AssertIntegrationEnabled(IntegrationId.Msmq); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/NLogTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/NLogTests.cs index 6edf56b73..b1ed8317f 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/NLogTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/NLogTests.cs @@ -38,11 +38,7 @@ public NLogTests(ITestOutputHelper output) public static IEnumerable GetTestData() { - foreach (var item in PackageVersions.NLog) - { - yield return item.Concat(false); - yield return item.Concat(true); - } + return PackageVersions.NLog; } [SkippableTheory] @@ -50,15 +46,10 @@ public static IEnumerable GetTestData() [Trait("Category", "EndToEnd")] [Trait("RunOnWindows", "True")] [Trait("SupportsInstrumentationVerification", "True")] - public void InjectsLogsWhenEnabled(string packageVersion, bool enableLogShipping) + public void InjectsLogsWhenEnabled(string packageVersion) { SetEnvironmentVariable("SIGNALFX_LOGS_INJECTION", "true"); SetInstrumentationVerification(); - using var logsIntake = new MockLogsIntake(); - if (enableLogShipping) - { - EnableDirectLogSubmission(logsIntake.Port, nameof(IntegrationId.NLog), nameof(InjectsLogsWhenEnabled)); - } var expectedCorrelatedTraceCount = 1; var expectedCorrelatedSpanCount = 1; @@ -80,15 +71,10 @@ public void InjectsLogsWhenEnabled(string packageVersion, bool enableLogShipping [Trait("Category", "EndToEnd")] [Trait("RunOnWindows", "True")] [Trait("SupportsInstrumentationVerification", "True")] - public void DoesNotInjectLogsWhenDisabled(string packageVersion, bool enableLogShipping) + public void DoesNotInjectLogsWhenDisabled(string packageVersion) { SetEnvironmentVariable("SIGNALFX_LOGS_INJECTION", "false"); SetInstrumentationVerification(); - using var logsIntake = new MockLogsIntake(); - if (enableLogShipping) - { - EnableDirectLogSubmission(logsIntake.Port, nameof(IntegrationId.NLog), nameof(InjectsLogsWhenEnabled)); - } var expectedCorrelatedTraceCount = 0; var expectedCorrelatedSpanCount = 0; @@ -106,49 +92,6 @@ public void DoesNotInjectLogsWhenDisabled(string packageVersion, bool enableLogS } } - [SkippableTheory] - [MemberData(nameof(PackageVersions.NLog), MemberType = typeof(PackageVersions))] - [Trait("Category", "EndToEnd")] - [Trait("RunOnWindows", "True")] - [Trait("SupportsInstrumentationVerification", "True")] - public void DirectlyShipsLogs(string packageVersion) - { - var hostName = "integration_nlog_tests"; - using var logsIntake = new MockLogsIntake(); - - SetInstrumentationVerification(); - SetEnvironmentVariable("SIGNALFX_LOGS_INJECTION", "true"); - EnableDirectLogSubmission(logsIntake.Port, nameof(IntegrationId.NLog), hostName); - - var agentPort = TcpPortProvider.GetOpenPort(); - using var agent = MockTracerAgent.Create(agentPort); - using var processResult = RunSampleAndWaitForExit(agent, packageVersion: packageVersion); - - Assert.True(processResult.ExitCode >= 0, $"Process exited with code {processResult.ExitCode} and exception: {processResult.StandardError}"); - - var logs = logsIntake.Logs; - - using var scope = new AssertionScope(); - logs.Should().NotBeNull(); - logs.Should().HaveCountGreaterOrEqualTo(3); - logs.Should() - .OnlyContain(x => x.Service == "LogsInjection.NLog") - .And.OnlyContain(x => x.Env == "integration_tests") - .And.OnlyContain(x => x.Version == "1.0.0") - .And.OnlyContain(x => x.Host == hostName) - .And.OnlyContain(x => x.Source == "csharp") - .And.OnlyContain(x => x.Exception == null) - .And.OnlyContain(x => x.LogLevel == DirectSubmissionLogLevel.Information); - - logs - .Where(x => !x.Message.Contains(ExcludeMessagePrefix)) - .Should() - .NotBeEmpty() - .And.OnlyContain(x => !string.IsNullOrEmpty(x.TraceId)) - .And.OnlyContain(x => !string.IsNullOrEmpty(x.SpanId)); - VerifyInstrumentation(processResult.Process); - } - private LogFileTest[] GetTestFiles(string packageVersion, bool logsInjectionEnabled = true) { if (packageVersion is null or "") diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/RabbitMQTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/RabbitMQTests.cs index 811a1f354..85b785660 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/RabbitMQTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/RabbitMQTests.cs @@ -54,7 +54,6 @@ public void SubmitsTraces(string packageVersion) int emptyBasicGetCount = 0; - using var telemetry = this.ConfigureTelemetry(); using (var agent = EnvironmentHelper.GetMockAgent()) using (RunSampleAndWaitForExit(agent, arguments: $"{TestPrefix}", packageVersion: packageVersion)) { @@ -243,7 +242,6 @@ public void SubmitsTraces(string packageVersion) Assert.Equal(2, exchangeDeclareCount); Assert.Equal(2, queueBindCount); Assert.Equal(8, queueDeclareCount); - telemetry.AssertIntegrationEnabled(IntegrationId.RabbitMQ); } private void AssertSpanName(MockSpan span, string operation) diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/SerilogTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/SerilogTests.cs index 413cb9a0e..37233ecac 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/SerilogTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/SerilogTests.cs @@ -38,11 +38,7 @@ public SerilogTests(ITestOutputHelper output) public static IEnumerable GetTestData() { - foreach (var item in PackageVersions.Serilog) - { - yield return item.Concat(false); - yield return item.Concat(true); - } + return PackageVersions.Serilog; } [SkippableTheory] @@ -50,15 +46,10 @@ public static IEnumerable GetTestData() [Trait("Category", "EndToEnd")] [Trait("RunOnWindows", "True")] [Trait("SupportsInstrumentationVerification", "True")] - public void InjectsLogsWhenEnabled(string packageVersion, bool enableLogShipping) + public void InjectsLogsWhenEnabled(string packageVersion) { SetEnvironmentVariable("SIGNALFX_LOGS_INJECTION", "true"); SetInstrumentationVerification(); - using var logsIntake = new MockLogsIntake(); - if (enableLogShipping) - { - EnableDirectLogSubmission(logsIntake.Port, nameof(IntegrationId.Serilog), nameof(InjectsLogsWhenEnabled)); - } var expectedCorrelatedTraceCount = 1; var expectedCorrelatedSpanCount = 1; @@ -80,15 +71,10 @@ public void InjectsLogsWhenEnabled(string packageVersion, bool enableLogShipping [Trait("Category", "EndToEnd")] [Trait("RunOnWindows", "True")] [Trait("SupportsInstrumentationVerification", "True")] - public void DoesNotInjectLogsWhenDisabled(string packageVersion, bool enableLogShipping) + public void DoesNotInjectLogsWhenDisabled(string packageVersion) { SetEnvironmentVariable("SIGNALFX_LOGS_INJECTION", "false"); SetInstrumentationVerification(); - using var logsIntake = new MockLogsIntake(); - if (enableLogShipping) - { - EnableDirectLogSubmission(logsIntake.Port, nameof(IntegrationId.Serilog), nameof(InjectsLogsWhenEnabled)); - } var expectedCorrelatedTraceCount = 0; var expectedCorrelatedSpanCount = 0; @@ -105,49 +91,6 @@ public void DoesNotInjectLogsWhenDisabled(string packageVersion, bool enableLogS } } - [SkippableTheory] - [MemberData(nameof(PackageVersions.Serilog), MemberType = typeof(PackageVersions))] - [Trait("Category", "EndToEnd")] - [Trait("RunOnWindows", "True")] - [Trait("SupportsInstrumentationVerification", "True")] - public void DirectlyShipsLogs(string packageVersion) - { - var hostName = "integration_serilog_tests"; - using var logsIntake = new MockLogsIntake(); - - SetInstrumentationVerification(); - SetEnvironmentVariable("SIGNALFX_LOGS_INJECTION", "true"); - EnableDirectLogSubmission(logsIntake.Port, nameof(IntegrationId.Serilog), hostName); - - var agentPort = TcpPortProvider.GetOpenPort(); - using var agent = MockTracerAgent.Create(agentPort); - using var processResult = RunSampleAndWaitForExit(agent, packageVersion: packageVersion); - - Assert.True(processResult.ExitCode >= 0, $"Process exited with code {processResult.ExitCode} and exception: {processResult.StandardError}"); - - var logs = logsIntake.Logs; - - using var scope = new AssertionScope(); - logs.Should().NotBeNull(); - logs.Should().HaveCountGreaterOrEqualTo(3); - logs.Should() - .OnlyContain(x => x.Service == "LogsInjection.Serilog") - .And.OnlyContain(x => x.Env == "integration_tests") - .And.OnlyContain(x => x.Version == "1.0.0") - .And.OnlyContain(x => x.Host == hostName) - .And.OnlyContain(x => x.Source == "csharp") - .And.OnlyContain(x => x.Exception == null) - .And.OnlyContain(x => x.LogLevel == DirectSubmissionLogLevel.Information); - - logs - .Where(x => !x.Message.Contains(ExcludeMessagePrefix)) - .Should() - .NotBeEmpty() - .And.OnlyContain(x => !string.IsNullOrEmpty(x.TraceId)) - .And.OnlyContain(x => !string.IsNullOrEmpty(x.SpanId)); - VerifyInstrumentation(processResult.Process); - } - private LogFileTest[] GetLogFiles(string packageVersion, bool logsInjectionEnabled) { var isPost200 = diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/ServiceStackRedisTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/ServiceStackRedisTests.cs index ce3d39994..365e80b64 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/ServiceStackRedisTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/ServiceStackRedisTests.cs @@ -32,7 +32,6 @@ public ServiceStackRedisTests(ITestOutputHelper output) [Trait("Category", "EndToEnd")] public async Task SubmitsTraces(string packageVersion) { - using var telemetry = this.ConfigureTelemetry(); using (var agent = EnvironmentHelper.GetMockAgent()) using (RunSampleAndWaitForExit(agent, arguments: $"{TestPrefix}", packageVersion: packageVersion)) { @@ -79,8 +78,6 @@ await VerifyHelper.VerifySpans( .ThenBy(x => x.Start) .ThenBy(x => x.Duration)); } - - telemetry.AssertIntegrationEnabled(IntegrationId.ServiceStackRedis); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/StackExchangeRedisTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/StackExchangeRedisTests.cs index ba91cc437..d5d3e260e 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/StackExchangeRedisTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/StackExchangeRedisTests.cs @@ -51,7 +51,6 @@ private enum PackageVersion public async Task SubmitsTraces(string packageVersion) { using var a = new AssertionScope(); - using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using (RunSampleAndWaitForExit(agent, arguments: $"{TestPrefix}", packageVersion: packageVersion)) { @@ -85,8 +84,6 @@ public async Task SubmitsTraces(string packageVersion) Assert.Contains(Tags.Version, (IDictionary)span.Tags); } - telemetry.AssertIntegrationEnabled(IntegrationId.StackExchangeRedis); - var settings = VerifyHelper.GetSpanVerifierSettings(); settings.UseFileName($"{nameof(StackExchangeRedisTests)}.{calculatedVersion}"); settings.DisableRequireUniquePrefix(); @@ -104,8 +101,6 @@ await VerifyHelper.VerifySpans( .ThenBy(x => x.Start) .ThenBy(x => x.Duration)); } - - telemetry.AssertIntegrationEnabled(IntegrationId.StackExchangeRedis); } private static PackageVersion GetPackageVersion(string packageVersionString) diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/TelemetryTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/TelemetryTests.cs deleted file mode 100644 index 10160f731..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/TelemetryTests.cs +++ /dev/null @@ -1,175 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System; -using System.Collections.Immutable; -using System.Threading.Tasks; -using Datadog.Trace.Configuration; -using Datadog.Trace.Telemetry; -using Datadog.Trace.TestHelpers; -using FluentAssertions; -using FluentAssertions.Execution; -using VerifyTests; -using VerifyXunit; -using Xunit; -using Xunit.Abstractions; - -namespace Datadog.Trace.ClrProfiler.IntegrationTests -{ - [UsesVerify] - public class TelemetryTests : TestHelper - { - private const int ExpectedSpans = 3; - private const string ServiceVersion = "1.0.0"; - - public TelemetryTests(ITestOutputHelper output) - : base("Telemetry", output) - { - SetEnvironmentVariable(ConfigurationKeys.FeatureFlags.ActivityListenerEnabled, "true"); - SetServiceVersion(ServiceVersion); - EnableDebugMode(); - } - - [SkippableFact] - [Trait("Category", "EndToEnd")] - [Trait("RunOnWindows", "True")] - public async Task Telemetry_Agentless_IsSentOnAppClose() - { - using var agent = MockTracerAgent.Create(useTelemetry: true); - Output.WriteLine($"Assigned port {agent.Port} for the agentPort."); - - using var telemetry = new MockTelemetryAgent(); - Output.WriteLine($"Assigned port {telemetry.Port} for the telemetry port."); - EnableTelemetry(standaloneAgentPort: telemetry.Port); - - int httpPort = TcpPortProvider.GetOpenPort(); - Output.WriteLine($"Assigning port {httpPort} for the httpPort."); - using (ProcessResult processResult = RunSampleAndWaitForExit(agent, arguments: $"Port={httpPort}")) - { - Assert.True(processResult.ExitCode == 0, $"Process exited with code {processResult.ExitCode}"); - - var spans = agent.WaitForSpans(ExpectedSpans); - - await AssertExpectedSpans(spans); - } - - var data = telemetry.AssertIntegrationEnabled(IntegrationId.HttpMessageHandler); - AssertTelemetry(data); - agent.Telemetry.Should().BeEmpty(); - } - - [SkippableFact(Skip = "SignalFX does not have cloud support for telemetry.")] - [Trait("Category", "EndToEnd")] - [Trait("RunOnWindows", "True")] - public async Task Telemetry_WithAgentProxy_IsSentOnAppClose() - { - using var agent = MockTracerAgent.Create(useTelemetry: true); - Output.WriteLine($"Assigned port {agent.Port} for the agentPort."); - - EnableTelemetry(); - - int httpPort = TcpPortProvider.GetOpenPort(); - Output.WriteLine($"Assigning port {httpPort} for the httpPort."); - using (ProcessResult processResult = RunSampleAndWaitForExit(agent, arguments: $"Port={httpPort}")) - { - Assert.True(processResult.ExitCode == 0, $"Process exited with code {processResult.ExitCode}"); - - var spans = agent.WaitForSpans(ExpectedSpans); - await AssertExpectedSpans(spans); - } - - var data = agent.AssertIntegrationEnabled(IntegrationId.HttpMessageHandler); - AssertTelemetry(data); - } - - [SkippableFact] - [Trait("Category", "EndToEnd")] - [Trait("RunOnWindows", "True")] - public async Task WhenDisabled_DoesntSendTelemetry() - { - using var agent = MockTracerAgent.Create(useTelemetry: true); - Output.WriteLine($"Assigned port {agent.Port} for the agentPort."); - - EnableTelemetry(enabled: false); - - int httpPort = TcpPortProvider.GetOpenPort(); - Output.WriteLine($"Assigning port {httpPort} for the httpPort."); - using (ProcessResult processResult = RunSampleAndWaitForExit(agent, arguments: $"Port={httpPort}")) - { - Assert.True(processResult.ExitCode == 0, $"Process exited with code {processResult.ExitCode}"); - - var spans = agent.WaitForSpans(ExpectedSpans); - await AssertExpectedSpans(spans); - } - - // Shouldn't have any, but wait for 5s - agent.WaitForLatestTelemetry(x => true); - agent.Telemetry.Should().BeEmpty(); - } - - [SkippableFact] - [Trait("Category", "EndToEnd")] - [Trait("RunOnWindows", "True")] - public async Task WhenUsingNamedPipesAgent_UsesNamedPipesTelemetry() - { - if (!EnvironmentTools.IsWindows()) - { - throw new SkipException("Can't use WindowsNamedPipes on non-Windows"); - } - - EnvironmentHelper.EnableWindowsNamedPipes(); - // The server implementation of named pipes is flaky so have 3 attempts - var attemptsRemaining = 3; - while (true) - { - try - { - attemptsRemaining--; - await RunTest(); - return; - } - catch (Exception ex) when (attemptsRemaining > 0 && ex is not SkipException) - { - Output.WriteLine($"Error executing test. {attemptsRemaining} attempts remaining. {ex}"); - } - } - - async Task RunTest() - { - using var agent = EnvironmentHelper.GetMockAgent(useTelemetry: true); - agent.Output = Output; - - int httpPort = TcpPortProvider.GetOpenPort(); - Output.WriteLine($"Assigning port {httpPort} for the httpPort."); - using (ProcessResult processResult = RunSampleAndWaitForExit(agent, arguments: $"Port={httpPort}")) - { - Assert.True(processResult.ExitCode == 0, $"Process exited with code {processResult.ExitCode}"); - - var spans = agent.WaitForSpans(ExpectedSpans); - await AssertExpectedSpans(spans); - } - - var data = agent.AssertIntegrationEnabled(IntegrationId.HttpMessageHandler); - - AssertTelemetry(data); - } - } - - private static void AssertTelemetry(TelemetryData data) - { - data.Application.ServiceVersion.Should().Be(ServiceVersion); - data.Application.ServiceName.Should().Be("Samples.Telemetry"); - } - - private static async Task AssertExpectedSpans(IImmutableList spans) - { - await VerifyHelper.VerifySpans(spans, VerifyHelper.GetSpanVerifierSettings()) - .DisableRequireUniquePrefix() - .UseFileName("TelemetryTests"); - } - } -} diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/TraceAnnotationsTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/TraceAnnotationsTests.cs index aa4c49274..43848d47c 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/TraceAnnotationsTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/TraceAnnotationsTests.cs @@ -88,7 +88,6 @@ public async Task SubmitTraces() SetEnvironmentVariable("SIGNALFX_TRACE_METHODS", ddTraceMethodsString); // Don't bother with telemetry when two assemblies are loaded because we could get unreliable results - MockTelemetryAgent telemetry = _twoAssembliesLoaded ? null : this.ConfigureTelemetry(); using (var agent = EnvironmentHelper.GetMockAgent()) using (RunSampleAndWaitForExit(agent)) { @@ -142,16 +141,11 @@ public async Task SubmitTraces() rootSpan.Start.Should().BeLessThan(remainingSpans.First().Start); (rootSpan.Start + rootSpan.Duration).Should().BeGreaterThan(lastEndTime.Value); - telemetry?.AssertIntegrationEnabled(IntegrationId.TraceAnnotations); - telemetry?.AssertConfiguration(ConfigTelemetryData.TraceMethods); - // Run snapshot verification var settings = VerifyHelper.GetSpanVerifierSettings(); await Verifier.Verify(orderedSpans, settings) .UseMethodName("_"); } - - telemetry?.Dispose(); } [SkippableFact] @@ -160,7 +154,6 @@ await Verifier.Verify(orderedSpans, settings) public void IntegrationDisabled() { // Don't bother with telemetry when two assemblies are loaded because we could get unreliable results - MockTelemetryAgent telemetry = _twoAssembliesLoaded ? null : this.ConfigureTelemetry(); SetEnvironmentVariable("SIGNALFX_TRACE_METHODS", string.Empty); SetEnvironmentVariable("SIGNALFX_TRACE_ANNOTATIONS_ENABLED", "false"); @@ -169,8 +162,6 @@ public void IntegrationDisabled() var spans = agent.WaitForSpans(1, 2000); Assert.Empty(spans); - telemetry?.AssertIntegration(IntegrationId.TraceAnnotations, enabled: false, autoEnabled: false); - telemetry?.Dispose(); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/TransportTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/TransportTests.cs index 28c0a45b9..d4bb9b51a 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/TransportTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/TransportTests.cs @@ -73,7 +73,6 @@ private async Task RunTest(TracesTransportType transportType) EnvironmentHelper.EnableTransport(GetTransport(transportType)); - using var telemetry = this.ConfigureTelemetry(); using var agent = GetAgent(transportType); agent.Output = Output; @@ -89,8 +88,6 @@ await VerifyHelper.VerifySpans(spans, VerifyHelper.GetSpanVerifierSettings()) .UseFileName("TransportTests"); } - telemetry.AssertConfiguration(ConfigTelemetryData.AgentTraceTransport, transportType.ToString()); - MockTracerAgent GetAgent(TracesTransportType type) => type switch { diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/WcfTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/WcfTests.cs index 1ac8a0fa8..f9798574c 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/WcfTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/WcfTests.cs @@ -72,7 +72,6 @@ public async Task SubmitsTraces(string binding, bool enableNewWcfInstrumentation const string expectedLogicScope = "wcf.request"; - using var telemetry = this.ConfigureTelemetry(); int wcfPort = 8585; using (var agent = EnvironmentHelper.GetMockAgent()) @@ -93,9 +92,6 @@ await Verifier.Verify(spans, settings) var result = span.IsWcf(); Assert.True(result.Success, result.ToString()); } - - // The custom binding doesn't trigger the integration - telemetry.AssertIntegration(IntegrationId.Wcf, enabled: binding != "Custom", autoEnabled: true); } } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/WebRequest20Tests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/WebRequest20Tests.cs index ea9cbce2b..8b29c9491 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/WebRequest20Tests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/WebRequest20Tests.cs @@ -39,7 +39,6 @@ public void SubmitsTraces() int httpPort = TcpPortProvider.GetOpenPort(); Output.WriteLine($"Assigning port {httpPort} for the httpPort."); - using var telemetry = this.ConfigureTelemetry(); using (var agent = EnvironmentHelper.GetMockAgent()) using (ProcessResult processResult = RunSampleAndWaitForExit(agent, arguments: $"Port={httpPort}")) { @@ -57,7 +56,6 @@ public void SubmitsTraces() } PropagationTestHelpers.AssertPropagationEnabled(spans.First(), processResult); - telemetry.AssertIntegrationEnabled(IntegrationId.WebRequest); } } @@ -71,7 +69,6 @@ public void TracingDisabled_DoesNotSubmitsTraces() SetInstrumentationVerification(); int httpPort = TcpPortProvider.GetOpenPort(); - using var telemetry = this.ConfigureTelemetry(); using (var agent = EnvironmentHelper.GetMockAgent()) using (ProcessResult processResult = RunSampleAndWaitForExit(agent, arguments: $"TracingDisabled Port={httpPort}")) { @@ -79,7 +76,6 @@ public void TracingDisabled_DoesNotSubmitsTraces() Assert.Equal(0, spans.Count); PropagationTestHelpers.AssertPropagationDisabled(processResult); - telemetry.AssertIntegrationDisabled(IntegrationId.WebRequest); VerifyInstrumentation(processResult.Process); } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/WebRequestTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/WebRequestTests.cs index 92b228ce7..f018ed2c2 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/WebRequestTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/WebRequestTests.cs @@ -42,7 +42,6 @@ public void SubmitsTraces() int httpPort = TcpPortProvider.GetOpenPort(); Output.WriteLine($"Assigning port {httpPort} for the httpPort."); - using var telemetry = this.ConfigureTelemetry(); using (var agent = EnvironmentHelper.GetMockAgent()) using (ProcessResult processResult = RunSampleAndWaitForExit(agent, arguments: $"Port={httpPort}")) { @@ -59,11 +58,6 @@ public void SubmitsTraces() PropagationTestHelpers.AssertPropagationEnabled(spans.First(), processResult); -#if NET7_0 - telemetry.AssertIntegrationEnabled(IntegrationId.HttpSocketsHandler); // uses HttpClient internally -#else - telemetry.AssertIntegrationEnabled(IntegrationId.WebRequest); -#endif VerifyInstrumentation(processResult.Process); } } @@ -79,7 +73,6 @@ public void TracingDisabled_DoesNotSubmitsTraces() int httpPort = TcpPortProvider.GetOpenPort(); - using var telemetry = this.ConfigureTelemetry(); using (var agent = EnvironmentHelper.GetMockAgent()) using (ProcessResult processResult = RunSampleAndWaitForExit(agent, arguments: $"TracingDisabled Port={httpPort}")) { @@ -88,11 +81,6 @@ public void TracingDisabled_DoesNotSubmitsTraces() PropagationTestHelpers.AssertPropagationDisabled(processResult); -#if NET7_0 - telemetry.AssertIntegrationDisabled(IntegrationId.HttpMessageHandler); // uses HttpClient internally -#else - telemetry.AssertIntegrationDisabled(IntegrationId.WebRequest); -#endif VerifyInstrumentation(processResult.Process); } } diff --git a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/ILogger/DirectSubmissionLoggerTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/ILogger/DirectSubmissionLoggerTests.cs deleted file mode 100644 index 66bb5cc5e..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/ILogger/DirectSubmissionLoggerTests.cs +++ /dev/null @@ -1,147 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#if NETCOREAPP - -using System; -using System.Collections.Concurrent; -using System.Text; -using System.Threading.Tasks; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission; -using Datadog.Trace.ClrProfiler.Managed.Tests.AutoInstrumentation.Logging.Serilog; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink; -using Datadog.Trace.TestHelpers; -using FluentAssertions; -using Microsoft.Extensions.Logging.Abstractions.Internal; -using Xunit; - -namespace Datadog.Trace.ClrProfiler.Managed.Tests.AutoInstrumentation.Logging.ILogger -{ - public class DirectSubmissionLoggerTests - { - [Fact] - public void LoggerEnqueuesLogMessage() - { - var sink = new TestSink(); - var logger = GetLogger(sink); - - var level = (int)DirectSubmissionLogLevel.Error; - logger.IsEnabled(level).Should().BeTrue(); - logger.Log( - logLevel: level, - eventId: 123, - state: "someValue", - exception: null, - (state, ex) => $"This is {state}"); - - sink.Events.Should().ContainSingle(); - } - - [Fact] - public void LoggerCanRenderLogMessage() - { - var sink = new TestSink(); - var formatter = LogSettingsHelper.GetFormatter(); - var logger = GetLogger(sink); - - var level = (int)DirectSubmissionLogLevel.Error; - logger.IsEnabled(level).Should().BeTrue(); - var state = "someValue"; - var eventId = 123; - logger.Log( - logLevel: level, - eventId: eventId, - state: state, - exception: null, - (s, ex) => $"This is {s}"); - - var log = sink.Events.Should().ContainSingle().Subject; - var sb = new StringBuilder(); - log.Format(sb, formatter); - - var formatted = sb.ToString(); - formatted.Should() - .NotBeNullOrWhiteSpace() - .And.Contain(state) - .And.Contain(eventId.ToString()) - .And.Contain($"This is {state}"); - } - - [Fact] - public void ShouldNotEmitLogWhenNotEnabled() - { - var sink = new TestSink(); - var formatter = LogSettingsHelper.GetFormatter(); - var logger = new DirectSubmissionLogger( - name: "TestLogger", - scopeProvider: new NullScopeProvider(), - sink: sink, - logFormatter: formatter, - minimumLogLevel: DirectSubmissionLogLevel.Information); - - var level = (int)DirectSubmissionLogLevel.Debug; - logger.IsEnabled(level).Should().BeFalse(); - logger.Log( - logLevel: level, - eventId: 123, - state: "someValue", - exception: null, - (s, ex) => $"This is {s}"); - - sink.Events.Should().BeEmpty(); - } - - private static DirectSubmissionLogger GetLogger(TestSink sink) - { - var settings = LogSettingsHelper.GetValidSettings(); - return new DirectSubmissionLogger( - name: "TestLogger", - scopeProvider: new NullScopeProvider(), - sink: sink, - logFormatter: LogSettingsHelper.GetFormatter(), - minimumLogLevel: settings.MinimumLevel); - } - - internal class TestSink : IDatadogSink - { - public ConcurrentQueue Events { get; } = new(); - - public void EnqueueLog(DatadogLogEvent logEvent) - { - Events.Enqueue(logEvent); - } - - public void Start() - { - } - - public Task FlushAsync() - { - return Task.CompletedTask; - } - - public Task DisposeAsync() - { - return Task.CompletedTask; - } - } - - internal class NullScopeProvider : IExternalScopeProvider - { - public IDisposable Push(object state) - { - return NullScope.Instance; - } - - public void ForEachScope(Action callback, TState state) - { - } - } - } -} - -#endif diff --git a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/ILogger/ILoggerDuckTypingTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/ILogger/ILoggerDuckTypingTests.cs deleted file mode 100644 index 6b30eabe1..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/ILogger/ILoggerDuckTypingTests.cs +++ /dev/null @@ -1,242 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -#if NETCOREAPP -using System; -using System.Collections.Generic; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink; -using Datadog.Trace.TestHelpers; -using FluentAssertions; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Console; -using Microsoft.Extensions.Options; -using Xunit; -using IExternalScopeProvider = Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.IExternalScopeProvider; -using ILoggerFactory = Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.ILoggerFactory; - -namespace Datadog.Trace.ClrProfiler.Managed.Tests.AutoInstrumentation.Logging.ILogger -{ - public class ILoggerDuckTypingTests - { - private readonly NullDatadogSink _sink; - private readonly LogFormatter _formatter; - private readonly Type _iloggerProviderType; - - public ILoggerDuckTypingTests() - { - _sink = new NullDatadogSink(); - _formatter = LogSettingsHelper.GetFormatter(); - _iloggerProviderType = LoggerFactoryIntegrationCommon.ProviderInterfaces; - } - - [Fact] - public void CanDuckTypeILoggerFactory() - { - var loggerFactory = new LoggerFactory(); - var testProvider = new ConsoleLoggerProvider(new DummyOptionsMonitor()); - - var proxy = loggerFactory.DuckCast(); - proxy.Should().NotBeNull(); - proxy.AddProvider(testProvider); - } - - [Fact] - public void CanReverseDuckTypeTestLogger() - { - var loggerFactory = new TestLogger(); - - var proxy = loggerFactory.DuckImplement(typeof(Microsoft.Extensions.Logging.ILogger)); - proxy.Should().NotBeNull(); - } - - [Fact] - public void CanReverseDuckTypeILogger() - { - var logger = new DirectSubmissionLogger("Test logger", null, _sink, _formatter, DirectSubmissionLogLevel.Debug); - var proxy = (Microsoft.Extensions.Logging.ILogger)logger.DuckImplement(typeof(Microsoft.Extensions.Logging.ILogger)); - - proxy.BeginScope(123).Should().NotBeNull(); - proxy.IsEnabled(LogLevel.Error).Should().BeTrue(); - proxy.Log(LogLevel.Error, "This is my message with a {Parameter}", 123); - } - - [Fact] - public void CanReverseDuckTypeILogger2() - { - var logger = new TestLogger(); - var proxy = (Microsoft.Extensions.Logging.ILogger)logger.DuckImplement(typeof(Microsoft.Extensions.Logging.ILogger)); - - proxy.BeginScope(123).Should().NotBeNull(); - proxy.IsEnabled(LogLevel.Error).Should().BeTrue(); - proxy.Log(LogLevel.Error, "This is my message with a {Parameter}", 123); - - logger.Logs.Should().ContainSingle("This is my message with a 123"); - } - - [Fact] - public void CanReverseDuckTypeILoggerProvider() - { - var loggerProvider = new DirectSubmissionLoggerProvider(_sink, _formatter, DirectSubmissionLogLevel.Debug); - var proxyProvider = (ILoggerProvider)loggerProvider.DuckImplement(_iloggerProviderType); - - var logger = proxyProvider.CreateLogger("Some category"); - - logger.BeginScope(123).Should().NotBeNull(); - logger.IsEnabled(LogLevel.Error).Should().BeTrue(); - logger.Log(LogLevel.Error, "This is my message with a {Parameter}", 123); - } - - [Fact] - public void CanAddLoggerProvider() - { - var loggerFactory = new LoggerFactory(); - var instance = loggerFactory.DuckCast(); - - var provider = new TestLoggerProvider(); - var proxy = provider.DuckImplement(_iloggerProviderType); - - instance.AddProvider(proxy); - - var logger = loggerFactory.CreateLogger("This is a test"); - - logger.BeginScope(123).Should().NotBeNull(); - logger.BeginScope("some string").Should().NotBeNull(); - logger.IsEnabled(LogLevel.Error).Should().BeTrue(); - logger.Log(LogLevel.Error, "This is my message with a {Parameter}", 123); - - provider.Logger.Logs.Should().ContainSingle("This is my message with a 123"); - } - - [Fact] - public void CanDuckTypeExternalScopeProvider() - { - var scopeProvider = new LoggerExternalScopeProvider(); - var proxy = scopeProvider.DuckCast(); - - proxy.Should().NotBeNull(); - using var scope = proxy.Push(123); - scope.Should().NotBeNull(); - } - - [Fact] - public void CanDuckTypeExternalScopeProviderAndUseWithProxyProvider() - { - var scopeProvider = new LoggerExternalScopeProvider(); - var loggerProvider = new DirectSubmissionLoggerProvider(new NullDatadogSink(), LogSettingsHelper.GetFormatter(), DirectSubmissionLogLevel.Debug); - var proxyProvider = (ISupportExternalScope)loggerProvider.DuckImplement(_iloggerProviderType); - proxyProvider.SetScopeProvider(scopeProvider); - - var logger = loggerProvider.CreateLogger("Test logger name"); - - using var scope = logger.BeginScope(123); - scope.Should().NotBeNull(); - logger.IsEnabled(3).Should().BeTrue(); - logger.Log(logLevel: 3, 12, state: 123, null, (state, ex) => $"This is my message with a {state}"); - } - - [Fact] - public void CanSetProviderUsingHelper() - { - var factory = new LoggerFactory(); - var loggerProvider = new DirectSubmissionLoggerProvider(new NullDatadogSink(), LogSettingsHelper.GetFormatter(), DirectSubmissionLogLevel.Debug); - LoggerFactoryIntegrationCommon.AddDirectSubmissionLoggerProvider(factory, loggerProvider); - } - - public sealed class DummyOptionsMonitor : IOptionsMonitor - { - public ConsoleLoggerOptions CurrentValue { get; } = new ConsoleLoggerOptions(); - - public IDisposable OnChange(Action listener) => null; - - public ConsoleLoggerOptions Get(string name) => CurrentValue; - } - - /// - /// Duck type for ILoggerProvider - /// - internal class TestLoggerProvider - { - public TestLogger Logger { get; } = new(); - - public IExternalScopeProvider ScopeProvider { get; private set; } - - /// - /// Creates a new instance. - /// - /// The category name for messages produced by the logger. - /// The instance of that was created. - [DuckReverseMethod] - public TestLogger CreateLogger(string categoryName) - { - return Logger; - } - - /// - [DuckReverseMethod] - public void Dispose() - { - } - - /// - /// Method for ISupportExternalScope - /// - /// The provider of scope data - [DuckReverseMethod(ParameterTypeNames = new[] { "Microsoft.Extensions.Logging.IExternalScopeProvider, Microsoft.Extensions.Logging.Abstractions" })] - public void SetScopeProvider(IExternalScopeProvider scopeProvider) - { - ScopeProvider = scopeProvider; - } - } - - internal class TestLogger - { - public List Logs { get; } = new(); - - [DuckReverseMethod(ParameterTypeNames = new[] - { - "Microsoft.Extensions.Logging.LogLevel, Microsoft.Extensions.Logging.Abstractions", - "Microsoft.Extensions.Logging.EventId, Microsoft.Extensions.Logging.Abstractions", - "TState", - "System.Exception", - "Func`3" - })] - public void Log(int logLevel, object eventId, TState state, Exception exception, Func formatter) - { - Logs.Add(formatter(state, exception)); - } - - /// - /// Checks if the given is enabled. - /// - /// Level to be checked. - /// true if enabled. - [DuckReverseMethod(ParameterTypeNames = new[] { "Microsoft.Extensions.Logging.LogLevel, Microsoft.Extensions.Logging.Abstractions" })] - public bool IsEnabled(int logLevel) => true; - - /// - /// Begins a logical operation scope. - /// - /// The identifier for the scope. - /// The type of the state to begin scope for. - /// An that ends the logical operation scope on dispose. - [DuckReverseMethod(ParameterTypeNames = new[] { "Microsoft.Extensions.Logging.LogLevel, Microsoft.Extensions.Logging.Abstractions" })] - public IDisposable BeginScope(TState state) => NullDisposable.Instance; - - private class NullDisposable : IDisposable - { - public static readonly NullDisposable Instance = new(); - - public void Dispose() - { - } - } - } - } -} -#endif diff --git a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/ILogger/LoggerLogFormatterTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/ILogger/LoggerLogFormatterTests.cs deleted file mode 100644 index 7cd56bfd4..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/ILogger/LoggerLogFormatterTests.cs +++ /dev/null @@ -1,117 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -#if NETCOREAPP -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.ILogger.DirectSubmission.Formatting; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.TestHelpers; -using FluentAssertions; -using Microsoft.Extensions.Logging; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Xunit; - -namespace Datadog.Trace.ClrProfiler.Managed.Tests.AutoInstrumentation.Logging.ILogger -{ - public class LoggerLogFormatterTests - { - [Fact] - public void SerializesEventCorrectly() - { - var formatter = LogSettingsHelper.GetFormatter(); - var scopeProvider = new LoggerExternalScopeProvider(); - var logger = new TestLogger(scopeProvider, formatter, new DateTime(2021, 09, 13, 10, 40, 57)); - - scopeProvider.Push(new Dictionary { { "OtherProperty", 62 } }); - scopeProvider.Push("Some other value"); - - logger.Log( - LogLevel.Debug, - new InvalidOperationException("Oops, just a test!"), - "This is a test with a {Value}", - 123); - - var expected = @"{""@t"":""2021-09-13T10:40:57.0000000Z"",""@m"":""This is a test with a 123"",""@l"":""Debug"",""@x"":""System.InvalidOperationException: Oops, just a test!"",""Value"":123,""OtherProperty"":62,""Scopes"":[""Some other value""]""@i"":""a9a87aee"",""ddsource"":""csharp"",""service"":""MyTestService"",""host"":""some_host""}"; - - logger.Logs.Should().ContainSingle(expected); - } - - [Fact] - public void DoesntAddPropertiesThatAreAlreadyAddedTwice() - { - var formatter = LogSettingsHelper.GetFormatter(); - var scopeProvider = new LoggerExternalScopeProvider(); - var logger = new TestLogger(scopeProvider, formatter, new DateTime(2021, 09, 13, 10, 40, 57)); - var properties = new Dictionary - { - { "Host", nameof(DoesntAddPropertiesThatAreAlreadyAddedTwice) + "host" }, - { "dd_service", nameof(DoesntAddPropertiesThatAreAlreadyAddedTwice) + "service" }, - { "ddsource", nameof(DoesntAddPropertiesThatAreAlreadyAddedTwice) + "source" }, - { "ddtags", nameof(DoesntAddPropertiesThatAreAlreadyAddedTwice) + ":tag" }, - }; - - using (scopeProvider.Push(properties)) - using (scopeProvider.Push("Another value")) - { - logger.Log( - LogLevel.Debug, - new InvalidOperationException("Oops, just a test!"), - "This is a test with a {Value} and a {Host}", - 123, - "some host"); - } - - var log = logger.Logs.Should().ContainSingle().Subject; - - var json = JObject.Parse(log); - - // should have all the added properties - foreach (var property in properties) - { - json.Properties() - .Where(x => string.Equals(property.Key, x.Name, StringComparison.OrdinalIgnoreCase)) - .Should() - .ContainSingle() - .Which.Value.ToString() - .Should() - .Be(property.Value.ToString()); - } - } - - internal class TestLogger : Microsoft.Extensions.Logging.ILogger - { - private readonly IExternalScopeProvider _provider; - private readonly LogFormatter _formatter; - private readonly DateTime _timestamp; - - public TestLogger(IExternalScopeProvider provider, LogFormatter formatter, DateTime timestamp) - { - _provider = provider; - _formatter = formatter; - _timestamp = timestamp; - } - - public List Logs { get; } = new(); - - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) - { - var provider = _provider.DuckCast(); - var logEntry = new LogEntry(_timestamp, (int)logLevel, "some_cat", eventId.GetHashCode(), state, exception, formatter, provider); - var log = LoggerLogFormatter.FormatLogEvent(_formatter, in logEntry); - Logs.Add(log); - } - - public bool IsEnabled(LogLevel logLevel) => true; - - public IDisposable BeginScope(TState state) => _provider.Push(state); - } - } -} -#endif diff --git a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Log4Net/DirectSubmissionLog4NetAppenderTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Log4Net/DirectSubmissionLog4NetAppenderTests.cs deleted file mode 100644 index 52663658a..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Log4Net/DirectSubmissionLog4NetAppenderTests.cs +++ /dev/null @@ -1,121 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Collections.Concurrent; -using System.Reflection; -using System.Text; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink; -using Datadog.Trace.TestHelpers; -using FluentAssertions; -using log4net; -using log4net.Appender; -using log4net.Config; -using log4net.Core; -using log4net.Util; -using Xunit; -using Level = log4net.Core.Level; - -namespace Datadog.Trace.ClrProfiler.Managed.Tests.AutoInstrumentation.Logging.Log4Net -{ - public class DirectSubmissionLog4NetAppenderTests - { - [Fact] - public void LoggerEnqueuesLogMessage() - { - var sink = new Log4NetHelper.TestSink(); - var appender = Log4NetHelper.GetAppender(sink, DirectSubmissionLogLevel.Debug); - - var level = Level.Error; - var logEvent = new LoggingEvent( - new LoggingEventData - { - Message = "This is {SomeValue}", - LoggerName = nameof(DirectSubmissionLog4NetAppenderTests), -#if LOG4NET_2 - TimeStampUtc = DateTime.UtcNow, -#else - TimeStamp = DateTime.Now, -#endif - Level = level, - Properties = new PropertiesDictionary { ["SomeValue"] = "someValue!" } - }); - - var proxy = Log4NetHelper.DuckCastLogEvent(logEvent); - appender.DoAppend(proxy); - - sink.Events.Should().ContainSingle(); - } - - [Fact] - public void ShouldNotEmitLogWhenNotEnabled() - { - var sink = new Log4NetHelper.TestSink(); - var appender = Log4NetHelper.GetAppender(sink, DirectSubmissionLogLevel.Warning); - - var level = Level.Info; - var logEvent = new LoggingEvent( - new LoggingEventData - { - Message = "This is {SomeValue}", - LoggerName = nameof(DirectSubmissionLog4NetAppenderTests), -#if LOG4NET_2 - TimeStampUtc = DateTime.UtcNow, -#else - TimeStamp = DateTime.Now, -#endif - Level = level, - Properties = new PropertiesDictionary { ["SomeValue"] = "someValue!" } - }); - - var proxy = Log4NetHelper.DuckCastLogEvent(logEvent); - appender.DoAppend(proxy); - - sink.Events.Should().BeEmpty(); - } - - [Fact] - public void LoggerIncludesPropertiesInLog() - { - var formatter = LogSettingsHelper.GetFormatter(); - var memoryAppender = new MemoryAppender(); - var sink = new Log4NetHelper.TestSink(); - var appender = Log4NetHelper.GetAppender(sink, DirectSubmissionLogLevel.Debug); - var appenderProxy = (IAppender)appender.DuckImplement(typeof(IAppender)); - var repository = log4net.LogManager.GetRepository(); - BasicConfigurator.Configure(repository, memoryAppender, appenderProxy); - var logger = LogManager.GetLogger(typeof(DirectSubmissionLog4NetAppenderTests)); - - // Set an ambient property - var someKey = "some key"; - var someValue = "some Value"; - log4net.ThreadContext.Properties[someKey] = someValue; - - // write the log - var message = "This is a value"; - logger.Error(message); - - // remove the context before rendering - log4net.ThreadContext.Properties.Remove(someKey); - - var logEvent = sink.Events.Should().ContainSingle().Subject; - - // get the rendered log - var sb = new StringBuilder(); - logEvent.Format(sb, formatter); - var log = sb.ToString(); - - log.Should() - .Contain(message) - .And.Contain(someKey) - .And.Contain(someValue) - .And.Contain(DirectSubmissionLogLevelExtensions.Error); - } - } -} diff --git a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Log4Net/Log4NetDuckTypingTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Log4Net/Log4NetDuckTypingTests.cs deleted file mode 100644 index 82fb3a009..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Log4Net/Log4NetDuckTypingTests.cs +++ /dev/null @@ -1,42 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission; -using FluentAssertions; -using log4net.Appender; -using Xunit; - -namespace Datadog.Trace.ClrProfiler.Managed.Tests.AutoInstrumentation.Logging.Log4Net -{ - public class Log4NetDuckTypingTests - { - [Fact] - public void CanIncreaseSizeOfIAppenderArray() - { - var appenders = new IAppender[] { }; - var results = Log4NetCommon.AddAppenderToResponse( - appenders, - new DirectSubmissionLog4NetAppender(null, 0)); - - results.Length.Should().Be(1); - } - - [Fact] - public void CanWriteLogToAppender() - { - var appenders = new IAppender[] { }; - var results = Log4NetCommon.AddAppenderToResponse( - appenders, - new DirectSubmissionLog4NetAppender(null, 0)); - - results.Length.Should().Be(1); - - foreach (var result in results) - { - result.Name.Should().Be("Datadog"); - } - } - } -} diff --git a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Log4Net/Log4NetHelper.cs b/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Log4Net/Log4NetHelper.cs deleted file mode 100644 index 194436be0..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Log4Net/Log4NetHelper.cs +++ /dev/null @@ -1,56 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Collections.Concurrent; -using System.Threading.Tasks; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Sink; -using log4net.Core; - -namespace Datadog.Trace.ClrProfiler.Managed.Tests.AutoInstrumentation.Logging.Log4Net -{ - internal class Log4NetHelper - { -#if LOG4NET_2 - public static DirectSubmissionLog4NetAppender GetAppender(IDatadogSink sink, DirectSubmissionLogLevel level) - => new(sink, level); - - public static ILoggingEventDuck DuckCastLogEvent(LoggingEvent logEvent) - => logEvent.DuckCast(); -#else - public static DirectSubmissionLog4NetLegacyAppender GetAppender(IDatadogSink sink, DirectSubmissionLogLevel level) - => new(sink, level); - - public static ILoggingEventLegacyDuck DuckCastLogEvent(LoggingEvent logEvent) - => logEvent.DuckCast(); -#endif - - internal class TestSink : IDatadogSink - { - public ConcurrentQueue Events { get; } = new(); - - public void EnqueueLog(DatadogLogEvent logEvent) - { - Events.Enqueue(logEvent); - } - - public void Start() - { - } - - public Task FlushAsync() - { - return Task.CompletedTask; - } - - public Task DisposeAsync() - { - return Task.CompletedTask; - } - } - } -} diff --git a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Log4Net/Log4NetLogFormatterTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Log4Net/Log4NetLogFormatterTests.cs deleted file mode 100644 index f78176f26..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Log4Net/Log4NetLogFormatterTests.cs +++ /dev/null @@ -1,75 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Reflection; -using System.Text; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Log4Net.DirectSubmission; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.TestHelpers; -using FluentAssertions; -using log4net.Core; -using log4net.Util; -using Xunit; - -namespace Datadog.Trace.ClrProfiler.Managed.Tests.AutoInstrumentation.Logging.Log4Net -{ - public class Log4NetLogFormatterTests - { - [Fact] - public void SerializesEventCorrectly() - { - var logEvent = GetLogEvent(); - var formatter = LogSettingsHelper.GetFormatter(); - var sb = new StringBuilder(); -#if LOG4NET_2 - var log = logEvent.DuckCast(); - Log4NetLogFormatter.FormatLogEvent(formatter, sb, log, log.TimeStampUtc); -#else - var log = logEvent.DuckCast(); - Log4NetLogFormatter.FormatLogEvent(formatter, sb, log, log.TimeStamp); -#endif - var actual = sb.ToString(); - - var expected = @"{""@t"":""2021-09-13T10:40:57.0000000Z"",""@m"":""This is a test with a 123"",""@l"":""Debug"",""@x"":""System.InvalidOperationException: Oops, just a test!"",""Value"":123,""@i"":""aad9c020"",""ddsource"":""csharp"",""service"":""MyTestService"",""dd_env"":""integration_tests"",""dd_version"":""1.0.0"",""host"":""some_host""}"; - actual.Should().Be(expected); - } - - private static LoggingEvent GetLogEvent() - { - var loggingEvent = new LoggingEvent( - typeof(Log4NetLogFormatterTests), - repository: null, - loggerName: "Something", - level: Level.Debug, - message: "This is a test with a 123", - exception: new InvalidOperationException("Oops, just a test!")); - loggingEvent.Properties["Value"] = 123; - - // Yes, this is very annoying - var loggingDate = new DateTimeOffset(2021, 09, 13, 10, 40, 57, TimeSpan.Zero).UtcDateTime; - var fieldInfo = typeof(LoggingEvent) - .GetField("m_data", BindingFlags.Instance | BindingFlags.NonPublic); - object boxed = fieldInfo!.GetValue(loggingEvent); - -#if LOG4NET_2 - typeof(LoggingEventData).GetProperty("TimeStampUtc")! - .SetValue(boxed, loggingDate); -#else - typeof(LoggingEventData).GetField("TimeStamp")! - .SetValue(boxed, loggingDate); -#endif - - fieldInfo.SetValue(loggingEvent, boxed); - -#if LOG4NET_2 - Assert.Equal(loggingDate, loggingEvent.TimeStampUtc); -#else - Assert.Equal(loggingDate, loggingEvent.TimeStamp); -#endif - return loggingEvent; - } - } -} diff --git a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/NLog/DirectSubmissionNLogTargetTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/NLog/DirectSubmissionNLogTargetTests.cs deleted file mode 100644 index c23a047ed..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/NLog/DirectSubmissionNLogTargetTests.cs +++ /dev/null @@ -1,124 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#if !NETCOREAPP -using System.Collections.Concurrent; -using System.Text; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies.Pre43; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink; -using Datadog.Trace.TestHelpers; -using FluentAssertions; -using NLog; -using NLog.Config; -using Xunit; - -namespace Datadog.Trace.ClrProfiler.Managed.Tests.AutoInstrumentation.Logging.NLog -{ - public class DirectSubmissionNLogTargetTests - { - [Fact] - public void LoggerEnqueuesLogMessage() - { - var sink = new NLogHelper.TestSink(); - var nlogSink = NLogHelper.CreateTarget(sink, DirectSubmissionLogLevel.Debug); - var targetProxy = (global::NLog.Targets.Target)NLogCommon.CreateNLogTargetProxy(nlogSink); - - var level = LogLevel.Error; - var logEvent = new LogEventInfo(level, nameof(LoggerEnqueuesLogMessage), "This is some value"); - - var proxy = NLogHelper.GetLogEventProxy(logEvent); - nlogSink.Write(proxy); - - sink.Events.Should().ContainSingle(); - } - - [Fact] - public void ShouldNotEmitLogWhenNotEnabled() - { - var sink = new NLogHelper.TestSink(); - var nlogSink = NLogHelper.CreateTarget(sink, DirectSubmissionLogLevel.Warning); - var targetProxy = (global::NLog.Targets.Target)NLogCommon.CreateNLogTargetProxy(nlogSink); - - var level = LogLevel.Info; - var logEvent = new LogEventInfo(level, nameof(LoggerEnqueuesLogMessage), "This is some value"); - - var proxy = NLogHelper.GetLogEventProxy(logEvent); - nlogSink.Write(proxy); - - sink.Events.Should().BeEmpty(); - } - - [Fact] - public void LoggerIncludesPropertiesInLog() - { - var formatter = LogSettingsHelper.GetFormatter(); - var sink = new NLogHelper.TestSink(); - var target = NLogHelper.CreateTarget(sink, DirectSubmissionLogLevel.Debug); - var targetProxy = NLogCommon.CreateNLogTargetProxy(target); - - var config = new LoggingConfiguration(); - NLogHelper.AddTargetToConfig(config, targetProxy); - - var logFactory = new LogFactory(config); - var logger = logFactory.GetLogger(nameof(LoggerIncludesPropertiesInLog)); - - // We don't currently record NDC/NDLC -#if NLOG_45 - var messageTemplate = "This is a message with {Value}"; -#else - var messageTemplate = "This is a message with {0}"; -#endif - var mdcKey = "some mdcKey"; - var mdcValue = "some mdcValue"; -#if !NLOG_2 - var mdclKey = "some mdclKey"; - var mdclValue = "some mdclValue"; -#endif - // var nestedScope = "some nested name"; - // var nestedDictionary = new Dictionary { { "nlcKey", 657 } }; - // var dictValues = nestedDictionary.First(); - try - { - MappedDiagnosticsContext.Set(mdcKey, mdcValue); -#if !NLOG_2 - MappedDiagnosticsLogicalContext.Set(mdclKey, mdclValue); -#endif - logger.Error(messageTemplate, 123); - } - finally - { - MappedDiagnosticsContext.Remove(mdcKey); -#if !NLOG_2 - MappedDiagnosticsLogicalContext.Remove(mdclKey); -#endif - } - - var logEvent = sink.Events.Should().ContainSingle().Subject; - - // get the rendered log - var sb = new StringBuilder(); - logEvent.Format(sb, formatter); - var log = sb.ToString(); - - log.Should() - .Contain("This is a message with 123") - .And.Contain(mdcKey) - .And.Contain(mdcValue) -#if !NLOG_2 - .And.Contain(mdclKey) - .And.Contain(mdclValue) -#endif - // .And.Contain(nestedScope) - // .And.Contain(dictValues.Key) - // .And.Contain(dictValues.Value.ToString()) - .And.Contain(DirectSubmissionLogLevelExtensions.Error); - } - } -} -#endif diff --git a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/NLog/NLogDuckTypingTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/NLog/NLogDuckTypingTests.cs deleted file mode 100644 index a14491648..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/NLog/NLogDuckTypingTests.cs +++ /dev/null @@ -1,273 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -#if !NETCOREAPP -using System; -using System.Linq; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies.Pre43; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Sink; -using FluentAssertions; -using NLog.Common; -using NLog.Config; -using NLog.Targets; -using Xunit; -using LogEventInfo = NLog.LogEventInfo; -using LogLevel = NLog.LogLevel; - -namespace Datadog.Trace.ClrProfiler.Managed.Tests.AutoInstrumentation.Logging.NLog -{ - public class NLogDuckTypingTests - { -#if NLOG_45 - [Fact] - public void CanDuckTypeLoggingConfigurationInModernNlog() - { - var instance = new LoggingConfiguration(); - instance.DuckCast(); - instance.TryDuckCast(out ILoggingConfigurationProxy duck).Should().BeTrue(); - duck.Should().NotBeNull(); - duck.ConfiguredNamedTargets.Cast().Should().BeEmpty(); - } - - [Fact] - public void CanDuckTypeLogInfoInModernNLog() - { - var instance = LogEventInfo.Create( - logLevel: LogLevel.Fatal, - loggerName: "LoggerName", - message: "Some message {Value}", - exception: new InvalidOperationException(), - formatProvider: null, - parameters: new object[] { 123 }); - - var duck = instance.DuckCast(); - duck.Should().NotBeNull(); - duck.Level.Should().NotBeNull(); - duck.Level.Ordinal.Should().Be(LogLevel.Fatal.Ordinal); - duck.FormattedMessage.Should().Be(instance.FormattedMessage); - duck.Exception.Should().Be(instance.Exception); - duck.HasProperties.Should().BeTrue(); - - var instanceWithoutProperties = LogEventInfo.Create( - logLevel: LogLevel.Fatal, - loggerName: "LoggerName", - message: "Some message"); - - instanceWithoutProperties.HasProperties.Should().BeFalse(); - var duckWithoutProperties = instanceWithoutProperties.DuckCast(); - - duckWithoutProperties.HasProperties.Should().BeFalse(); - - instanceWithoutProperties.Properties["TestKey"] = "TestValue"; - duckWithoutProperties.HasProperties.Should().BeTrue(); - duckWithoutProperties.Properties.Should().ContainKey("TestKey").WhoseValue.Should().Be("TestValue"); - } -#elif NLOG_43 - [Fact] - public void CanDuckTypeLoggingConfigurationLegacyInLegacyNlog() - { - var instance = new LoggingConfiguration(); - instance.DuckCast(); - instance.TryDuckCast(out LoggingConfigurationLegacyProxy duck).Should().BeTrue(); - duck.Should().NotBeNull(); - duck.ConfiguredNamedTargets.Should().BeEmpty(); - } -#elif NLOG_2 || NLOG_30 - [Fact] - public void CanDuckTypeLoggingConfigurationLegacyPre43InAncientNlog() - { - var instance = new LoggingConfiguration(); - instance.LoggingRules.Should().BeEmpty(); - instance.DuckCast(); - instance.TryDuckCast(out LoggingConfigurationPre43Proxy duck).Should().BeTrue(); - duck.Should().NotBeNull(); - duck.ConfiguredNamedTargets.Should().BeEmpty(); - var rule = new LoggingRule(); - duck.LoggingRules.Add(rule); - instance.LoggingRules.Should().ContainSingle().Which.Should().Be(rule); - } - - [Fact] - public void CanDuckTypeLoggingRuleInPre43() - { - var rule = new LoggingRule(); - var proxy = rule.DuckCast(); - - proxy.LoggerNamePattern = "TEST"; - for (int i = 0; i < 6; i++) - { - proxy.LogLevels[i] = true; - } - - rule.LoggerNamePattern.Should().Be("TEST"); - rule.Levels - ?.Select(x => x.Ordinal) - .Should() - .NotBeNull() - .And.ContainInOrder(0, 1, 2, 3, 4, 5); - } -#endif - - [Fact] - public void CanReverseDuckTypeTarget() - { - var targetType = typeof(Target); - var target = NLogHelper.CreateTarget(new NullDatadogSink(), DirectSubmissionLogLevel.Debug); - var proxy = NLogCommon.CreateNLogTargetProxy(target); - - proxy.Should().NotBeNull(); - proxy.GetType().Should().BeDerivedFrom(targetType); - - var message = "the message"; - var logInfo = new AsyncLogEventInfo(LogEventInfo.Create(LogLevel.Error, "test", message), _ => { }); - var typedProxy = ((Target)proxy); - typedProxy.WriteAsyncLogEvent(logInfo); // should not throw - -#if NLOG_45 - var proxyOfProxy = proxy.DuckCast(); - proxyOfProxy.Should().NotBeNull(); - - var results = proxyOfProxy.GetAllProperties(logInfo.LogEvent.DuckCast()); - results.Should().NotBeNull(); - - target.SetBaseProxy(proxyOfProxy); -#endif - } - -#if !NLOG_45 - [Fact] - public void CanDuckTypeLogInfoInLegacyNLog() - { -#if NLOG_2 - var instance = new LogEventInfo( - level: LogLevel.Fatal, - loggerName: "LoggerName", - message: "Some message {0}", - exception: new InvalidOperationException(), - formatProvider: null, - parameters: new object[] { 123 }); -#else - var instance = LogEventInfo.Create( - logLevel: LogLevel.Fatal, - loggerName: "LoggerName", - message: "Some message {0}", - exception: new InvalidOperationException(), - formatProvider: null, - parameters: new object[] { 123 }); -#endif - var duck = instance.DuckCast(); - duck.Should().NotBeNull(); - duck.Level.Should().NotBeNull(); - duck.Level.Ordinal.Should().Be(LogLevel.Fatal.Ordinal); - duck.LoggerName.Should().Be(instance.LoggerName); - duck.FormattedMessage.Should().Be(instance.FormattedMessage); - duck.Exception.Should().Be(instance.Exception); - duck.HasProperties.Should().BeFalse(); - - instance.Properties["TestKey"] = "TestValue"; - duck.HasProperties.Should().BeTrue(); - duck.Properties.Should().ContainKey("TestKey").WhichValue.Should().Be("TestValue"); - } - - [Fact] - public void CanDuckTypeMdc() - { - var assembly = typeof(Target).Assembly; - NLogCommon.TryGetMdcProxy( - assembly, - out var haveProxy, - out var isModernMdcProxy, - out var mdc, - out var mdcLegacy); - haveProxy.Should().BeTrue(); - if (isModernMdcProxy) - { - mdc.Should().NotBeNull(); - mdc.GetNames().Should().BeEmpty(); - } - else - { - mdcLegacy.ThreadDictionary.Should().BeEmpty(); - } - - var key = "mykey"; - var value = "myvalue"; - global::NLog.MappedDiagnosticsContext.Set(key, value); - if (isModernMdcProxy) - { - var containsKey = mdc.GetNames().Should().NotBeNull().And.ContainSingle().Subject; - mdc.GetObject(containsKey) - .Should() - .NotBeNull() - .And.Be(value); - - global::NLog.MappedDiagnosticsContext.Remove(key); - mdc.GetNames().Should().BeEmpty(); - } - else - { - mdcLegacy.ThreadDictionary.Keys.Cast().Should().ContainSingle(key); - mdcLegacy.ThreadDictionary[key].Should().Be(value); - - global::NLog.MappedDiagnosticsContext.Remove(key); - mdcLegacy.ThreadDictionary.Should().BeEmpty(); - } - } - -#if !NLOG_2 - [Fact] - public void CanDuckTypeMdlc() - { - var assembly = typeof(Target).Assembly; - NLogCommon.TryGetMdlcProxy( - assembly, - out var haveProxy, - out var isModernMdlcProxy, - out var mdlc, - out var mdlcLegacy); - haveProxy.Should().BeTrue(); - - if (isModernMdlcProxy) - { - mdlc.Should().NotBeNull(); - mdlc.GetNames().Should().BeEmpty(); - } - else - { - mdlcLegacy.LogicalThreadDictionary.Should().BeEmpty(); - } - - var key = "mykey"; - var value = "myvalue"; - global::NLog.MappedDiagnosticsLogicalContext.Set(key, value); - if (isModernMdlcProxy) - { - var containsKey = mdlc.GetNames().Should().NotBeNull().And.ContainSingle().Subject; - mdlc.GetObject(containsKey) - .Should() - .NotBeNull() - .And.Be(value); - - global::NLog.MappedDiagnosticsLogicalContext.Remove(key); - mdlc.GetNames().Should().BeEmpty(); - } - else - { - mdlcLegacy.LogicalThreadDictionary.Keys.Cast().Should().ContainSingle(key); - mdlcLegacy.LogicalThreadDictionary[key].Should().Be(value); - - global::NLog.MappedDiagnosticsLogicalContext.Remove(key); - mdlcLegacy.LogicalThreadDictionary.Should().BeEmpty(); - } - } -#endif -#endif - } -} -#endif diff --git a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/NLog/NLogHelper.cs b/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/NLog/NLogHelper.cs deleted file mode 100644 index 581413294..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/NLog/NLogHelper.cs +++ /dev/null @@ -1,72 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#if !NETCOREAPP -using System.Collections.Concurrent; -using System.Threading.Tasks; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Proxies; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink; -using Datadog.Trace.TestHelpers; -using NLog; -using NLog.Config; - -namespace Datadog.Trace.ClrProfiler.Managed.Tests.AutoInstrumentation.Logging.NLog -{ - internal static class NLogHelper - { -#if NLOG_45 - public static DirectSubmissionNLogTarget CreateTarget(IDatadogSink sink, DirectSubmissionLogLevel minimumLevel) - => new(sink, minimumLevel, LogSettingsHelper.GetFormatter()); - - public static ILogEventInfoProxy GetLogEventProxy(LogEventInfo logEvent) - => logEvent.DuckCast(); - - public static void AddTargetToConfig(LoggingConfiguration config, object targetProxy) - => NLogCommon.AddDatadogTargetNLog45(config, targetProxy); -#else - public static DirectSubmissionNLogLegacyTarget CreateTarget(IDatadogSink sink, DirectSubmissionLogLevel minimumLevel) - => new(sink, minimumLevel, SettingsHelper.GetFormatter()); - - public static LogEventInfoLegacyProxy GetLogEventProxy(LogEventInfo logEvent) - => logEvent.DuckCast(); -#endif - -#if NLOG_43 - public static void AddTargetToConfig(LoggingConfiguration config, object targetProxy) - => NLogCommon.AddDatadogTargetNLog43To45(config, targetProxy); -#elif !NLOG_45 - public static void AddTargetToConfig(LoggingConfiguration config, object targetProxy) - => NLogCommon.AddDatadogTargetNLogPre43(config, targetProxy); -#endif - - public class TestSink : IDatadogSink - { - public ConcurrentQueue Events { get; } = new(); - - public void EnqueueLog(DatadogLogEvent logEvent) - { - Events.Enqueue(logEvent); - } - - public void Start() - { - } - - public Task FlushAsync() - { - return Task.CompletedTask; - } - - public Task DisposeAsync() - { - return Task.CompletedTask; - } - } - } -} -#endif diff --git a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/NLog/NLogLogFormatterTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/NLog/NLogLogFormatterTests.cs deleted file mode 100644 index 304b18bdc..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/NLog/NLogLogFormatterTests.cs +++ /dev/null @@ -1,81 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -#if !NETCOREAPP -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.NLog.DirectSubmission.Formatting; -using Datadog.Trace.TestHelpers; -using FluentAssertions; -using NLog; -using Xunit; - -namespace Datadog.Trace.ClrProfiler.Managed.Tests.AutoInstrumentation.Logging.NLog -{ - public class NLogLogFormatterTests - { - [Fact] - public void SerializesEventCorrectlyWhenPropertiesAreAvailable() - { - var logEvent = GetLogEvent(); - var log = NLogHelper.GetLogEventProxy(logEvent); - var properties = new Dictionary - { - { "Value", 123 }, - { "OtherProperty", 62 }, - }; - - var wrapper = new LogEntry(log, properties, fallbackProperties: null); - - var formatter = LogSettingsHelper.GetFormatter(); - - var sb = new StringBuilder(); - NLogLogFormatter.FormatLogEvent(formatter, sb, wrapper); - var actual = sb.ToString(); - - var expected = @"{""@t"":""2021-09-13T10:40:57.0000000Z"",""@m"":""This is a test with a 123"",""@l"":""Debug"",""@x"":""System.InvalidOperationException: Oops, just a test!"",""Value"":123,""OtherProperty"":62,""@i"":""e5450052"",""ddsource"":""csharp"",""service"":""MyTestService"",""dd_env"":""integration_tests"",""dd_version"":""1.0.0"",""host"":""some_host""}"; - actual.Should().Be(expected); - } - - [Fact] - public void SerializesEventCorrectlyWhenUsingFallbackProperties() - { - var logEvent = GetLogEvent(); - var log = NLogHelper.GetLogEventProxy(logEvent); - var fallback = new Dictionary - { - { "Value", 123 }, - { "OtherProperty", 62 }, - }; - - var wrapper = new LogEntry(log, properties: null, fallback); - - var formatter = LogSettingsHelper.GetFormatter(); - - var sb = new StringBuilder(); - NLogLogFormatter.FormatLogEvent(formatter, sb, wrapper); - var actual = sb.ToString(); - - var expected = @"{""@t"":""2021-09-13T10:40:57.0000000Z"",""@m"":""This is a test with a 123"",""@l"":""Debug"",""@x"":""System.InvalidOperationException: Oops, just a test!"",""Value"":123,""OtherProperty"":62,""@i"":""e5450052"",""ddsource"":""csharp"",""service"":""MyTestService"",""dd_env"":""integration_tests"",""dd_version"":""1.0.0"",""host"":""some_host""}"; - actual.Should().Be(expected); - } - - private static LogEventInfo GetLogEvent() - { - return new LogEventInfo( - LogLevel.Debug, - loggerName: nameof(NLogLogFormatterTests), - message: "This is a test with a {0}", - formatProvider: CultureInfo.InvariantCulture, - parameters: new object[] { 123 }, - exception: new InvalidOperationException("Oops, just a test!")) - { - TimeStamp = new DateTime(2021, 09, 13, 10, 40, 57, DateTimeKind.Utc), - }; - } - } -} -#endif diff --git a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Serilog/DirectSubmissionSerilogSinkTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Serilog/DirectSubmissionSerilogSinkTests.cs deleted file mode 100644 index 04448e0b9..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Serilog/DirectSubmissionSerilogSinkTests.cs +++ /dev/null @@ -1,89 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Collections.Concurrent; -using System.Linq; -using System.Text; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink; -using Datadog.Trace.TestHelpers; -using Datadog.Trace.Vendors.Serilog.Capturing; -using Datadog.Trace.Vendors.Serilog.Core; -using Datadog.Trace.Vendors.Serilog.Events; -using FluentAssertions; -using Xunit; -using static Datadog.Trace.ClrProfiler.Managed.Tests.AutoInstrumentation.Logging.Serilog.SerilogHelper; - -namespace Datadog.Trace.ClrProfiler.Managed.Tests.AutoInstrumentation.Logging.Serilog -{ - public class DirectSubmissionSerilogSinkTests - { - [Fact] - public void LoggerEnqueuesLogMessage() - { - var sink = new TestSink(); - var serilogSink = new DirectSubmissionSerilogSink(sink, DirectSubmissionLogLevel.Debug); - - var level = LogEventLevel.Error; - GetSerilogMessageProcessor() - .Process("This is {SomeValue}", new object[] { "someValue" }, out var parsedTemplate, out var boundProperties); - var logEvent = new LogEvent(DateTimeOffset.Now, level, exception: null, parsedTemplate, boundProperties); - - var proxy = logEvent.DuckCast(); - serilogSink.Emit(proxy); - - sink.Events.Should().ContainSingle(); - } - - [Fact] - public void LoggerCanRenderLogMessage() - { - var sink = new TestSink(); - var serilogSink = new DirectSubmissionSerilogSink(sink, DirectSubmissionLogLevel.Debug); - - var level = LogEventLevel.Error; - var rawText = "someValue"; - GetSerilogMessageProcessor() - .Process("This is {SomeValue}", new object[] { "someValue" }, out var parsedTemplate, out var boundProperties); - var logEvent = new LogEvent(DateTimeOffset.Now, level, exception: null, parsedTemplate, boundProperties); - - var proxy = logEvent.DuckCast(); - serilogSink.Emit(proxy); - - var log = sink.Events.Should().ContainSingle().Subject; - var sb = new StringBuilder(); - var formatter = LogSettingsHelper.GetFormatter(); - log.Format(sb, formatter); - - var formatted = sb.ToString(); - formatted.Should() - .NotBeNullOrWhiteSpace() - .And.Contain(rawText) - .And.Contain($@"This is \""{rawText}\"""); - } - - [Fact] - public void ShouldNotEmitLogWhenNotEnabled() - { - var sink = new TestSink(); - var serilogSink = new DirectSubmissionSerilogSink(sink, DirectSubmissionLogLevel.Warning); - - var level = LogEventLevel.Information; - GetSerilogMessageProcessor() - .Process("This is {SomeValue}", new object[] { "someValue" }, out var parsedTemplate, out var boundProperties); - var logEvent = new LogEvent(DateTimeOffset.Now, level, exception: null, parsedTemplate, boundProperties); - - var proxy = logEvent.DuckCast(); - serilogSink.Emit(proxy); - - sink.Events.Should().BeEmpty(); - } - } -} diff --git a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Serilog/SerilogDuckTypingTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Serilog/SerilogDuckTypingTests.cs deleted file mode 100644 index 031d768f9..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Serilog/SerilogDuckTypingTests.cs +++ /dev/null @@ -1,213 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Collections.Generic; -using System.Linq; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.Formatting; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Vendors.Serilog; -using Datadog.Trace.Vendors.Serilog.Core; -using Datadog.Trace.Vendors.Serilog.Events; -using Datadog.Trace.Vendors.Serilog.Parsing; -using FluentAssertions; -using FluentAssertions.Execution; -using Xunit; -using static Datadog.Trace.ClrProfiler.Managed.Tests.AutoInstrumentation.Logging.Serilog.SerilogHelper; - -namespace Datadog.Trace.ClrProfiler.Managed.Tests.AutoInstrumentation.Logging.Serilog -{ - public class SerilogDuckTypingTests - { - [Fact] - public void CanDuckTypeMessageTemplate() - { - var instance = new Vendors.Serilog.Events.MessageTemplate("Some text", Enumerable.Empty()); - instance.TryDuckCast(out MessageTemplateProxy duck).Should().BeTrue(); - duck.Should().NotBeNull(); - duck.Text.Should().Be(instance.Text); - } - - [Fact] - public void CanDuckTypeLogEvent() - { - var instance = new LogEvent( - DateTimeOffset.UtcNow, - LogEventLevel.Error, - new Exception(), - new Vendors.Serilog.Events.MessageTemplate("Some text", Enumerable.Empty()), - new[] { new LogEventProperty("SomeProp", new ScalarValue(123)) }); - - instance.TryDuckCast(out ILogEvent duck).Should().BeTrue(); - var intLevel = (int)instance.Level; - var intLevel2 = (int)duck.Level; - duck.Should().NotBeNull(); - duck.Exception.Should().Be(instance.Exception); - intLevel2.Should().Be(intLevel); - duck.Timestamp.Should().Be(instance.Timestamp); - duck.MessageTemplate.Text.Should().Be(instance.MessageTemplate.Text); - var properties = new List(); - - foreach (var duckProperty in duck.Properties) - { - properties.Add(duckProperty.DuckCast()); - } - - foreach (var property in instance.Properties) - { - properties.Should() - .ContainSingle( - x => x.Key == property.Key - && x.Value.ToString() == property.Value.ToString()); - } - } - - [Fact] - public void CanDuckTypeLoggerConfiguration() - { - var config = new LoggerConfiguration(); - - config.TryDuckCast(out ILoggerConfiguration duckConfig).Should().BeTrue(); - duckConfig.Should().NotBeNull(); - duckConfig.LogEventSinks.Cast().Should().BeEmpty(); - - Type sinkType = typeof(ILogEventSink); - var sink = new TestSerilogSink(); - - var duckSink = sink.DuckImplement(sinkType); - duckConfig.LogEventSinks.Add(duckSink); - - var logger = config.CreateLogger(); - var message = "This is a test"; - logger.Information(message); - - sink.Logs.Should().ContainSingle(x => x == message); - } - - [Fact] - public void CanReverseDuckTypeSerilogSink() - { - var sink = new DirectSubmissionSerilogSink( - new TestSink(), - DirectSubmissionLogLevel.Information); - - Type sinkType = typeof(ILogEventSink); - var duckSink = (ILogEventSink)sink.DuckImplement(sinkType); - - GetSerilogMessageProcessor() - .Process("This is {SomeValue}", new object[] { "someValue" }, out var parsedTemplate, out var boundProperties); - var logEvent = new LogEvent(DateTimeOffset.Now, LogEventLevel.Information, exception: null, parsedTemplate, boundProperties); - - duckSink.Emit(logEvent); - } - - [Theory] - [InlineData(123)] - [InlineData("test")] - [InlineData(1.23)] - public void CanDuckTypeScalarLogValue(object value) - { - var scalar = new ScalarValue(value); - - scalar.TryDuckCast(out var duck).Should().BeTrue(); - duck.Value.Should().Be(value); - } - - [Theory] - [InlineData(123, 456, 789)] - [InlineData("test", "testage")] - [InlineData(1.23, 4.56)] - public void CanDuckTypeSequenceValue(params object[] values) - { - var seq = new SequenceValue(values.Select(x => new ScalarValue(x))); - - seq.TryDuckCast(out var duck).Should().BeTrue(); - duck.Should().NotBeNull(); - using var scope = new AssertionScope(); - var wrappedValues = new object[values.Length]; - var i = 0; - foreach (var element in duck.Elements) - { - element.TryDuckCast(out var scalar).Should().BeTrue(); - wrappedValues[i] = scalar.Value; - i++; - } - - wrappedValues.Should().ContainInOrder(values); - } - - [Theory] - [InlineData(123, 456, 789)] - [InlineData("test", "testage")] - [InlineData(1.23, 4.56)] - public void CanDuckTypeStructureValue(params object[] values) - { - var typeTag = "MyTestClass"; - var structure = new StructureValue( - values.Select((x, i) => new LogEventProperty($"Value{i}", new ScalarValue(x))), - typeTag); - - structure.TryDuckCast(out var duck).Should().BeTrue(); - duck.Should().NotBeNull(); - duck.TypeTag.Should().Be(typeTag); - - var duckValues = duck.Properties - .Cast() - .Select(x => x.DuckCast()) - .ToList(); - - duckValues.Select(x => x.Name) - .Should() - .ContainInOrder(values.Select((_, i) => $"Value{i}")); - - duckValues.Select(x => x.Value.DuckCast().Value) - .Should() - .ContainInOrder(values); - } - - [Theory] - [InlineData(123, 456, 789)] - [InlineData("test", "testage")] - [InlineData(1.23, 4.56)] - public void CanDuckTypeDictionaryValue(params object[] values) - { - var dict = new DictionaryValue( - values.Select( - (x, i) => new KeyValuePair( - new ScalarValue($"Value{i}"), - new ScalarValue(x)))); - - dict.TryDuckCast(out var duck).Should().BeTrue(); - duck.Should().NotBeNull(); - - var duckValues = duck.Elements - .Cast() - .Select(x => x.DuckCast()) - .ToList(); - - duckValues.Select(x => x.Key.DuckCast().Value) - .Should() - .ContainInOrder(values.Select((_, i) => $"Value{i}")); - - duckValues.Select(x => x.Value.DuckCast().Value) - .Should() - .ContainInOrder(values); - } - - internal class TestSerilogSink - { - public List Logs { get; } = new(); - - [DuckReverseMethod(ParameterTypeNames = new[] { "Datadog.Trace.Vendors.Serilog.Events.LogEvent, Datadog.Trace" })] - public void Emit(ILogEvent logEvent) - { - Logs.Add(logEvent.RenderMessage()); - } - } - } -} diff --git a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Serilog/SerilogHelper.cs b/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Serilog/SerilogHelper.cs deleted file mode 100644 index bf3c414b4..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Serilog/SerilogHelper.cs +++ /dev/null @@ -1,55 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Collections.Concurrent; -using System.Linq; -using System.Threading.Tasks; -using Datadog.Trace.Logging.DirectSubmission.Sink; -using Datadog.Trace.Vendors.Serilog.Capturing; -using Datadog.Trace.Vendors.Serilog.Core; - -namespace Datadog.Trace.ClrProfiler.Managed.Tests.AutoInstrumentation.Logging.Serilog -{ - internal static class SerilogHelper - { - public static MessageTemplateProcessor GetSerilogMessageProcessor() - { - // Use some "default" values - return new MessageTemplateProcessor( - new PropertyValueConverter( - maximumDestructuringDepth: 10, - maximumStringLength: int.MaxValue, - maximumCollectionCount: int.MaxValue, - additionalScalarTypes: Enumerable.Empty(), - additionalDestructuringPolicies: Enumerable.Empty(), - propagateExceptions: false)); - } - - internal class TestSink : IDatadogSink - { - public ConcurrentQueue Events { get; } = new(); - - public void EnqueueLog(DatadogLogEvent logEvent) - { - Events.Enqueue(logEvent); - } - - public void Start() - { - } - - public Task FlushAsync() - { - return Task.CompletedTask; - } - - public Task DisposeAsync() - { - return Task.CompletedTask; - } - } - } -} diff --git a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Serilog/SerilogLogFormatterTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Serilog/SerilogLogFormatterTests.cs deleted file mode 100644 index 702844fe3..000000000 --- a/tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/Serilog/SerilogLogFormatterTests.cs +++ /dev/null @@ -1,66 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission.Formatting; -using Datadog.Trace.Configuration; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.TestHelpers; -using Datadog.Trace.Vendors.Serilog; -using Datadog.Trace.Vendors.Serilog.Events; -using Datadog.Trace.Vendors.Serilog.Parsing; -using FluentAssertions; -using Xunit; - -namespace Datadog.Trace.ClrProfiler.Managed.Tests.AutoInstrumentation.Logging.Serilog -{ - public class SerilogLogFormatterTests - { - [Fact] - public void SerializesEventCorrectly() - { - var logEvent = GetLogEvent(); - var log = logEvent.DuckCast(); - - var formatter = LogSettingsHelper.GetFormatter(); - - var sb = new StringBuilder(); - SerilogLogFormatter.FormatLogEvent(formatter, sb, log); - var actual = sb.ToString(); - - var expected = @"{""@t"":""2021-09-13T10:40:57.0000000Z"",""@m"":""This is a test with a 123"",""@l"":""Debug"",""@x"":""System.InvalidOperationException: Oops, just a test!"",""Value"":123,""OtherProperty"":62,""@i"":""a9a87aee"",""ddsource"":""csharp"",""service"":""MyTestService"",""dd_env"":""integration_tests"",""dd_version"":""1.0.0"",""host"":""some_host""}"; - actual.Should().Be(expected); - } - - private static LogEvent GetLogEvent() - { - new LoggerConfiguration() - .CreateLogger() - .BindMessageTemplate( - "This is a test with a {Value}", - new object[] { 123 }, - out var messageTemplate, - out var boundProperties); - - // simulate properties added via scopes - boundProperties = boundProperties - .Concat(new[] { new LogEventProperty("OtherProperty", new ScalarValue(62)) }); - - return new LogEvent( - timestamp: new DateTimeOffset(2021, 09, 13, 10, 40, 57, TimeSpan.Zero), - LogEventLevel.Debug, - exception: new InvalidOperationException("Oops, just a test!"), - messageTemplate: messageTemplate, - boundProperties); - } - } -} diff --git a/tracer/test/Datadog.Trace.IntegrationTests/TelemetryTransportTests.cs b/tracer/test/Datadog.Trace.IntegrationTests/TelemetryTransportTests.cs deleted file mode 100644 index 7f2484679..000000000 --- a/tracer/test/Datadog.Trace.IntegrationTests/TelemetryTransportTests.cs +++ /dev/null @@ -1,128 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Net; -using System.Threading.Tasks; -using Datadog.Trace.Configuration; -using Datadog.Trace.Telemetry; -using Datadog.Trace.Telemetry.Transports; -using Datadog.Trace.TestHelpers; -using FluentAssertions; -using Xunit; - -namespace Datadog.Trace.IntegrationTests -{ - public class TelemetryTransportTests - { - [SkippableFact] - public async Task CanSendTelemetry() - { - using var agent = new MockTelemetryAgent(TcpPortProvider.GetOpenPort()); - var telemetryUri = new Uri($"http://localhost:{agent.Port}"); - - // Uses framework specific transport - var transport = TelemetryTransportFactory.Create( - new TelemetrySettings(telemetryEnabled: true, configurationError: null, agentlessSettings: null), - new ImmutableExporterSettings(new ExporterSettings { AgentUri = telemetryUri })); - var data = GetSampleData(); - - var result = await transport.PushTelemetry(data); - - result.Should().Be(TelemetryPushResult.Success); - var received = agent.WaitForLatestTelemetry(x => x.SeqId == data.SeqId); - - received.Should().NotBeNull(); - - // check some basic values - received.SeqId.Should().Be(data.SeqId); - received.Application.Env.Should().Be(data.Application.Env); - received.Application.ServiceName.Should().Be(data.Application.ServiceName); - } - - [SkippableFact] - public async Task WhenNoListener_ReturnsFatalError() - { - // Nothing listening on this port (currently) - var port = TcpPortProvider.GetOpenPort(); - var telemetryUri = new Uri($"http://localhost:{port}"); - - // Uses framework specific transport - var transport = TelemetryTransportFactory.Create( - new TelemetrySettings(telemetryEnabled: true, configurationError: null, agentlessSettings: null), - new ImmutableExporterSettings(new ExporterSettings { AgentUri = telemetryUri })); - var data = GetSampleData(); - - var result = await transport.PushTelemetry(data); - - result.Should().Be(TelemetryPushResult.FatalError); - } - - [SkippableTheory] - [InlineData(200, (int)TelemetryPushResult.Success)] - [InlineData(201, (int)TelemetryPushResult.Success)] - [InlineData(400, (int)TelemetryPushResult.TransientFailure)] - [InlineData(404, (int)TelemetryPushResult.FatalError)] - [InlineData(500, (int)TelemetryPushResult.TransientFailure)] - [InlineData(503, (int)TelemetryPushResult.TransientFailure)] - public async Task ReturnsExpectedPushResultForStatusCode(int responseCode, int expectedPushResult) - { - using var agent = new ErroringTelemetryAgent(responseCode: responseCode, port: TcpPortProvider.GetOpenPort()); - var telemetryUri = new Uri($"http://localhost:{agent.Port}"); - - // Uses framework specific transport - var transport = TelemetryTransportFactory.Create( - new TelemetrySettings(telemetryEnabled: true, configurationError: null, agentlessSettings: null), - new ImmutableExporterSettings(new ExporterSettings { AgentUri = telemetryUri })); - var data = GetSampleData(); - - var result = await transport.PushTelemetry(data); - - result.Should().Be((TelemetryPushResult)expectedPushResult); - } - - private static TelemetryData GetSampleData() - { - return new TelemetryData( - requestType: TelemetryRequestTypes.AppHeartbeat, - tracerTime: 1234, - runtimeId: "some-value", - seqId: 23, - application: new ApplicationTelemetryData( - serviceName: "TelemetryTransportTests", - env: "TracerTelemetryTest", - tracerVersion: TracerConstants.AssemblyVersion, - languageName: "dotnet", - languageVersion: "1.2.3"), - host: new HostTelemetryData(), - payload: null); - } - - internal class ErroringTelemetryAgent : MockTelemetryAgent - { - private readonly int _responseCode; - - public ErroringTelemetryAgent(int responseCode, int port) - : base(port) - { - _responseCode = responseCode; - } - - protected override void HandleHttpRequest(HttpListenerContext ctx) - { - OnRequestReceived(ctx); - - // make sure it works correctly - var telemetry = DeserializeResponse(ctx.Request.InputStream); - - // NOTE: HttpStreamRequest doesn't support Transfer-Encoding: Chunked - // (Setting content-length avoids that) - - ctx.Response.StatusCode = _responseCode; - ctx.Response.Close(); - } - } - } -} diff --git a/tracer/test/Datadog.Trace.TestHelpers/EnvironmentHelper.cs b/tracer/test/Datadog.Trace.TestHelpers/EnvironmentHelper.cs index 1f3efcbc4..15701bbc1 100644 --- a/tracer/test/Datadog.Trace.TestHelpers/EnvironmentHelper.cs +++ b/tracer/test/Datadog.Trace.TestHelpers/EnvironmentHelper.cs @@ -274,11 +274,6 @@ public void SetEnvironmentVariables( // set consistent env name (can be overwritten by custom environment variable) environmentVariables["SIGNALFX_ENV"] = "integration_tests"; - environmentVariables[ConfigurationKeys.Telemetry.Enabled] = agent.TelemetryEnabled.ToString(); - if (agent.TelemetryEnabled) - { - environmentVariables[ConfigurationKeys.Telemetry.AgentlessEnabled] = "0"; - } // Don't attach the profiler to these processes environmentVariables["SIGNALFX_PROFILER_EXCLUDE_PROCESSES"] = diff --git a/tracer/test/Datadog.Trace.TestHelpers/LogSettingsHelper.cs b/tracer/test/Datadog.Trace.TestHelpers/LogSettingsHelper.cs deleted file mode 100644 index 56cfa0875..000000000 --- a/tracer/test/Datadog.Trace.TestHelpers/LogSettingsHelper.cs +++ /dev/null @@ -1,38 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System; -using System.Collections.Generic; -using System.Linq; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink.PeriodicBatching; - -namespace Datadog.Trace.TestHelpers -{ - internal class LogSettingsHelper - { - public static LogFormatter GetFormatter() => new( - GetValidSettings(), - serviceName: "MyTestService", - env: "integration_tests", - version: "1.0.0"); - - public static ImmutableDirectLogSubmissionSettings GetValidSettings() - { - return ImmutableDirectLogSubmissionSettings.Create( - host: "some_host", - source: "csharp", - intakeUrl: "https://localhost:1234", - accessToken: "abcdef", - minimumLevel: DirectSubmissionLogLevel.Debug, - globalTags: new Dictionary(), - enabledLogShippingIntegrations: ImmutableDirectLogSubmissionSettings.SupportedIntegrations.Select(x => x.ToString()).ToList(), - batchingOptions: new BatchingSinkOptions(1000, 100_000, TimeSpan.FromSeconds(2))); - } - } -} diff --git a/tracer/test/Datadog.Trace.TestHelpers/MockLogsIntake.cs b/tracer/test/Datadog.Trace.TestHelpers/MockLogsIntake.cs deleted file mode 100644 index c36a9efdc..000000000 --- a/tracer/test/Datadog.Trace.TestHelpers/MockLogsIntake.cs +++ /dev/null @@ -1,259 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Collections.Specialized; -using System.IO; -using System.Net; -using System.Text; -using System.Threading; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Vendors.Newtonsoft.Json; -using Datadog.Trace.Vendors.Newtonsoft.Json.Linq; - -namespace Datadog.Trace.TestHelpers -{ - public class MockLogsIntake : IDisposable - { - private static readonly JsonSerializer JsonSerializer = new(); - private readonly HttpListener _listener; - private readonly Thread _listenerThread; - private readonly CancellationTokenSource _cancellationTokenSource; - - public MockLogsIntake(int? initialPort = null, int retries = 5) - { - _cancellationTokenSource = new CancellationTokenSource(); - var port = initialPort ?? TcpPortProvider.GetOpenPort(); - - // try up to 5 consecutive ports before giving up - while (true) - { - // seems like we can't reuse a listener if it fails to start, - // so create a new listener each time we retry - var listener = new HttpListener(); - listener.Prefixes.Add($"http://127.0.0.1:{port}/"); - listener.Prefixes.Add($"http://localhost:{port}/"); - listener.Prefixes.Add($"http://127.0.0.1:{port}/v1/input/"); - listener.Prefixes.Add($"http://localhost:{port}/v1/input/"); - listener.Prefixes.Add($"http://127.0.0.1:{port}/api/v2/logs/"); - listener.Prefixes.Add($"http://localhost:{port}/api/v2/logs/"); - - try - { - listener.Start(); - - // successfully listening - Port = port; - _listener = listener; - - _listenerThread = new Thread(HandleHttpRequests); - _listenerThread.IsBackground = true; - _listenerThread.Start(); - - return; - } - catch (HttpListenerException) when (retries > 0) - { - // only catch the exception if there are retries left - port = TcpPortProvider.GetOpenPort(); - retries--; - } - - // always close listener if exception is thrown, - // whether it was caught or not - listener.Close(); - } - } - - public event EventHandler> RequestReceived; - - public event EventHandler>> RequestDeserialized; - - /// - /// Gets the TCP port that this intake is listening on. - /// Can be different from 's initialPort - /// parameter if listening on that port fails. - /// - public int Port { get; } - - public IImmutableList Logs { get; private set; } = ImmutableList.Empty; - - public IImmutableList RequestHeaders { get; private set; } = ImmutableList.Empty; - - /// - /// Gets or sets a value indicating whether to skip deserialization of traces. - /// - public bool ShouldDeserializeLogs { get; set; } = true; - - public void Dispose() - { - _listener?.Stop(); - _cancellationTokenSource.Cancel(); - } - - private void AssertHeader( - NameValueCollection headers, - string headerKey, - Func assertion) - { - var header = headers.Get(headerKey); - - if (string.IsNullOrEmpty(header)) - { - throw new Exception($"Every submission to the intake should have a {headerKey} header."); - } - - if (!assertion(header)) - { - throw new Exception($"Failed assertion for {headerKey} on {header}"); - } - } - - private void HandleHttpRequests() - { - while (_listener.IsListening) - { - try - { - var ctx = _listener.GetContext(); - RequestReceived?.Invoke(this, new EventArgs(ctx)); - if (ShouldDeserializeLogs) - { - var logs = Log.DeserializeFromStream(ctx.Request.InputStream); - RequestDeserialized?.Invoke(this, new EventArgs>(logs)); - - lock (this) - { - // we only need to lock when replacing the logs collection, - // not when reading it because it is immutable - Logs = Logs.AddRange(logs); - RequestHeaders = RequestHeaders.Add(new NameValueCollection(ctx.Request.Headers)); - } - } - - // NOTE: HttpStreamRequest doesn't support Transfer-Encoding: Chunked - // (Setting content-length avoids that) - - ctx.Response.ContentType = "application/json"; - var buffer = Encoding.UTF8.GetBytes("{}"); - ctx.Response.ContentLength64 = buffer.LongLength; - ctx.Response.OutputStream.Write(buffer, 0, buffer.Length); - ctx.Response.Close(); - } - catch (HttpListenerException) - { - // listener was stopped, - // ignore to let the loop end and the method return - } - catch (ObjectDisposedException) - { - // the response has been already disposed. - } - catch (InvalidOperationException) - { - // this can occur when setting Response.ContentLength64, with the framework claiming that the response has already been submitted - // for now ignore, and we'll see if this introduces downstream issues - } - catch (Exception) when (!_listener.IsListening) - { - // we don't care about any exception when listener is stopped - } - } - } - - public class Log - { - [JsonProperty("@t")] - public DateTimeOffset Timestamp { get; set; } - - [JsonProperty("@m")] - public string Message { get; set; } - - [JsonProperty("@i")] - public string EventId { get; set; } - - [JsonProperty("@x")] - public Exception Exception { get; set; } - - // Not required, defaults to Information if not provided - [JsonProperty("@l")] - public DirectSubmissionLogLevel LogLevel { get; set; } = DirectSubmissionLogLevel.Information; - - [JsonProperty("ddsource")] - public string Source { get; set; } - - [JsonProperty("host")] - public string Host { get; set; } - - [JsonProperty("ddtags")] - public string Tags { get; set; } - - [JsonProperty("dd_env")] - public string Env { get; set; } - - [JsonProperty("dd_version")] - public string Version { get; set; } - - [JsonProperty("dd_service")] - public string Service { get; set; } - - [JsonProperty("dd_trace_id")] - public string TraceId { get; set; } - - [JsonProperty("dd_span_id")] - public string SpanId { get; set; } - - [JsonExtensionData] - internal Dictionary OtherProperties { get; } = new(); - - [JsonProperty("service")] - private string Service1 - { - set => Service = value; - } - - [JsonProperty("dd.service")] - private string Service2 - { - set => Service = value; - } - - [JsonProperty("trace_id")] - private string TraceId1 - { - set => TraceId = value; - } - - [JsonProperty("span_id")] - private string SpanId1 - { - set => SpanId = value; - } - - [JsonProperty("dd.env")] - private string Env2 - { - set => Env = value; - } - - [JsonProperty("dd.version")] - private string Version2 - { - set => Version = value; - } - - public static List DeserializeFromStream(Stream stream) - { - using var sr = new StreamReader(stream); - using var jsonTextReader = new JsonTextReader(sr); - return JsonSerializer.Deserialize>(jsonTextReader); - } - } - } -} diff --git a/tracer/test/Datadog.Trace.TestHelpers/MockTelemetryAgent.cs b/tracer/test/Datadog.Trace.TestHelpers/MockTelemetryAgent.cs deleted file mode 100644 index 878da289a..000000000 --- a/tracer/test/Datadog.Trace.TestHelpers/MockTelemetryAgent.cs +++ /dev/null @@ -1,228 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Collections.Specialized; -using System.IO; -using System.Net; -using System.Net.Sockets; -using System.Threading; -using System.Threading.Tasks; -using Datadog.Trace.Telemetry; -using Datadog.Trace.Telemetry.Transports; -using Datadog.Trace.Vendors.Newtonsoft.Json; - -namespace Datadog.Trace.TestHelpers -{ - public class MockTelemetryAgent : IDisposable - { - // Needs to be kept in sync with JsonTelemetryTransport.SerializerSettings, but with the additional converter - private static readonly JsonSerializer Serializer = JsonSerializer.Create(new JsonSerializerSettings - { - NullValueHandling = JsonTelemetryTransport.SerializerSettings.NullValueHandling, - ContractResolver = JsonTelemetryTransport.SerializerSettings.ContractResolver, - Converters = new List { new PayloadConverter() }, - }); - - private readonly HttpListener _listener; - private readonly Thread _listenerThread; - - public MockTelemetryAgent(int port = 8524, int retries = 5) - { - // try up to 5 consecutive ports before giving up - while (true) - { - // seems like we can't reuse a listener if it fails to start, - // so create a new listener each time we retry - var listener = new HttpListener(); - listener.Prefixes.Add($"http://127.0.0.1:{port}/"); - listener.Prefixes.Add($"http://localhost:{port}/"); - - try - { - listener.Start(); - - // successfully listening - Port = port; - _listener = listener; - - _listenerThread = new Thread(HandleHttpRequests); - _listenerThread.Start(); - - return; - } - catch (HttpListenerException) when (retries > 0) - { - // only catch the exception if there are retries left - port = TcpPortProvider.GetOpenPort(); - retries--; - } - catch - { - // always close listener if exception is thrown, - // whether it was caught or not - listener.Close(); - throw; - } - - // always close listener if exception is thrown, - // whether it was caught or not - listener.Close(); - } - } - - public event EventHandler> RequestReceived; - - /// - /// Gets or sets a value indicating whether to skip serialization of traces. - /// - public bool ShouldDeserializeTraces { get; set; } = true; - - /// - /// Gets the TCP port that this Agent is listening on. - /// Can be different from 's initialPort - /// parameter if listening on that port fails. - /// - public int Port { get; } - - public ConcurrentStack Telemetry { get; } = new(); - - public IImmutableList RequestHeaders { get; private set; } = ImmutableList.Empty; - - /// - /// Wait for the telemetry condition to be satisfied. - /// Note that the first telemetry that satisfies the condition is returned - /// To retrieve all telemetry received, use - /// - /// A predicate for the current telemetry - /// The timeout - /// The time between checks - /// The telemetry that satisfied - public T WaitForLatestTelemetry( - Func hasExpectedValues, - int timeoutInMilliseconds = 5000, - int sleepTime = 200) - { - var deadline = DateTime.UtcNow.AddMilliseconds(timeoutInMilliseconds); - - T latest = default; - while (DateTime.UtcNow < deadline) - { - if (Telemetry.TryPeek(out latest) && hasExpectedValues(latest)) - { - break; - } - - Thread.Sleep(sleepTime); - } - - return latest; - } - - public void Dispose() - { - _listener?.Close(); - } - - internal static T DeserializeResponse(Stream inputStream) - { - T telemetry; - using (var sr = new StreamReader(inputStream)) - using (var jsonTextReader = new JsonTextReader(sr)) - { - telemetry = Serializer.Deserialize(jsonTextReader); - } - - return telemetry; - } - - protected virtual void OnRequestReceived(HttpListenerContext context) - { - RequestReceived?.Invoke(this, new EventArgs(context)); - } - - protected virtual void HandleHttpRequest(HttpListenerContext ctx) - { - OnRequestReceived(ctx); - - var telemetry = DeserializeResponse(ctx.Request.InputStream); - Telemetry.Push(telemetry); - - lock (this) - { - RequestHeaders = RequestHeaders.Add(new NameValueCollection(ctx.Request.Headers)); - } - - // NOTE: HttpStreamRequest doesn't support Transfer-Encoding: Chunked - // (Setting content-length avoids that) - - ctx.Response.StatusCode = 200; - ctx.Response.Close(); - } - - private void HandleHttpRequests() - { - while (_listener.IsListening) - { - try - { - var ctx = _listener.GetContext(); - HandleHttpRequest(ctx); - } - catch (HttpListenerException) - { - // listener was stopped, - // ignore to let the loop end and the method return - } - catch (ObjectDisposedException) - { - // the response has been already disposed. - } - catch (InvalidOperationException) - { - // this can occur when setting Response.ContentLength64, with the framework claiming that the response has already been submitted - // for now ignore, and we'll see if this introduces downstream issues - } - catch (Exception) when (!_listener.IsListening) - { - // we don't care about any exception when listener is stopped - } - } - } - - internal class PayloadConverter : JsonConverter - { - public override bool CanConvert(Type objectType) - { - return objectType == typeof(IPayload); - } - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - // use the default serialization - it works fine - serializer.Serialize(writer, value); - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - object payload = serializer.Deserialize(reader); - - payload ??= serializer.Deserialize(reader); - payload ??= serializer.Deserialize(reader); - payload ??= serializer.Deserialize(reader); - - if (payload is null) - { - throw new Exception("Unknown IPayload type"); - } - - return payload; - } - } - } -} diff --git a/tracer/test/Datadog.Trace.TestHelpers/MockTracerAgent.cs b/tracer/test/Datadog.Trace.TestHelpers/MockTracerAgent.cs index 1e333b724..4b612cfa9 100644 --- a/tracer/test/Datadog.Trace.TestHelpers/MockTracerAgent.cs +++ b/tracer/test/Datadog.Trace.TestHelpers/MockTracerAgent.cs @@ -78,15 +78,8 @@ protected MockTracerAgent(bool telemetryEnabled, TestTransports transport) public ConcurrentQueue StatsdRequests { get; } = new(); - /// - /// Gets the requests received by the telemetry endpoint - /// - public ConcurrentStack Telemetry { get; } = new(); - public ITestOutputHelper Output { get; set; } - public IImmutableList TelemetryRequestHeaders { get; private set; } = ImmutableList.Empty; - /// /// Gets or sets a value indicating whether to skip deserialization of traces. /// @@ -189,37 +182,6 @@ public IImmutableList WaitForSpans( return relevantSpans; } - /// - /// Wait for the telemetry condition to be satisfied. - /// Note that the first telemetry that satisfies the condition is returned - /// To retrieve all telemetry received, use - /// - /// A predicate for the current telemetry. - /// The object passed to the func will be a instance - /// The timeout - /// The time between checks - /// The telemetry that satisfied - public object WaitForLatestTelemetry( - Func hasExpectedValues, - int timeoutInMilliseconds = 5000, - int sleepTime = 200) - { - var deadline = DateTime.UtcNow.AddMilliseconds(timeoutInMilliseconds); - - object latest = default; - while (DateTime.UtcNow < deadline) - { - if (Telemetry.TryPeek(out latest) && hasExpectedValues(latest)) - { - break; - } - - Thread.Sleep(sleepTime); - } - - return latest; - } - public IImmutableList WaitForStats( int count, int timeoutInMilliseconds = 20000) @@ -405,44 +367,6 @@ private protected void HandlePotentialTraces(MockHttpParser.MockHttpRequest requ } } - private protected void HandlePotentialTelemetryData(MockHttpParser.MockHttpRequest request) - { - if (request.ContentLength >= 1) - { - try - { - var body = ReadStreamBody(request); - using var stream = new MemoryStream(body); - - var telemetry = MockTelemetryAgent.DeserializeResponse(stream); - Telemetry.Push(telemetry); - - lock (this) - { - var headerCollection = new NameValueCollection(); - foreach (var header in request.Headers) - { - headerCollection.Add(header.Name, header.Value); - } - - TelemetryRequestHeaders = TelemetryRequestHeaders.Add(headerCollection); - } - } - catch (Exception ex) - { - var message = ex.Message.ToLowerInvariant(); - - if (message.Contains("beyond the end of the stream")) - { - // Accept call is likely interrupted by a dispose - // Swallow the exception and let the test finish - } - - throw; - } - } - } - private void AssertHeader( NameValueCollection headers, string headerKey, @@ -707,71 +631,54 @@ private void HandleHttpRequests() ctx.Response.AddHeader("Datadog-Agent-Version", Version); } - if (TelemetryEnabled && (ctx.Request.Url?.AbsolutePath.StartsWith("/" + TelemetryConstants.AgentTelemetryEndpoint) ?? false)) - { - // telemetry request - var telemetry = MockTelemetryAgent.DeserializeResponse(ctx.Request.InputStream); - Telemetry.Push(telemetry); + var buffer = Encoding.UTF8.GetBytes("{}"); - lock (this) - { - TelemetryRequestHeaders = TelemetryRequestHeaders.Add(new NameValueCollection(ctx.Request.Headers)); - } - - ctx.Response.StatusCode = 200; + if (ctx.Request.RawUrl.EndsWith("/info")) + { + var endpoints = $"{{\"endpoints\":{JsonConvert.SerializeObject(DiscoveryService.AllSupportedEndpoints)}}}"; + buffer = Encoding.UTF8.GetBytes(endpoints); } - else + else if (ctx.Request.RawUrl.Contains("/debugger/v1/input")) { - var buffer = Encoding.UTF8.GetBytes("{}"); - - if (ctx.Request.RawUrl.EndsWith("/info")) - { - var endpoints = $"{{\"endpoints\":{JsonConvert.SerializeObject(DiscoveryService.AllSupportedEndpoints)}}}"; - buffer = Encoding.UTF8.GetBytes(endpoints); - } - else if (ctx.Request.RawUrl.Contains("/debugger/v1/input")) + using var body = ctx.Request.InputStream; + using var streamReader = new StreamReader(body); + var batch = streamReader.ReadToEnd(); + ReceiveDebuggerBatch(batch); + } + else if (ShouldDeserializeTraces) + { + if (ctx.Request.Url?.AbsolutePath == "/v0.6/stats") { - using var body = ctx.Request.InputStream; - using var streamReader = new StreamReader(body); - var batch = streamReader.ReadToEnd(); - ReceiveDebuggerBatch(batch); + var statsPayload = MessagePackSerializer.Deserialize(ctx.Request.InputStream); + OnStatsDeserialized(statsPayload); + + lock (this) + { + Stats = Stats.Add(statsPayload); + } } - else if (ShouldDeserializeTraces) + else { - if (ctx.Request.Url?.AbsolutePath == "/v0.6/stats") - { - var statsPayload = MessagePackSerializer.Deserialize(ctx.Request.InputStream); - OnStatsDeserialized(statsPayload); + // assume trace request + var spans = MessagePackSerializer.Deserialize>>(ctx.Request.InputStream); + OnRequestDeserialized(spans); - lock (this) - { - Stats = Stats.Add(statsPayload); - } - } - else + lock (this) { - // assume trace request - var spans = MessagePackSerializer.Deserialize>>(ctx.Request.InputStream); - OnRequestDeserialized(spans); - - lock (this) - { - // we only need to lock when replacing the span collection, - // not when reading it because it is immutable - Spans = Spans.AddRange(spans.SelectMany(trace => trace)); - RequestHeaders = RequestHeaders.Add(new NameValueCollection(ctx.Request.Headers)); - } + // we only need to lock when replacing the span collection, + // not when reading it because it is immutable + Spans = Spans.AddRange(spans.SelectMany(trace => trace)); + RequestHeaders = RequestHeaders.Add(new NameValueCollection(ctx.Request.Headers)); } } - - ctx.Response.ContentType = "application/json"; - ctx.Response.ContentLength64 = buffer.LongLength; - ctx.Response.OutputStream.Write(buffer, 0, buffer.Length); } + ctx.Response.ContentType = "application/json"; + ctx.Response.ContentLength64 = buffer.LongLength; + ctx.Response.OutputStream.Write(buffer, 0, buffer.Length); + // NOTE: HttpStreamRequest doesn't support Transfer-Encoding: Chunked // (Setting content-length avoids that) - ctx.Response.Close(); } catch (HttpListenerException) @@ -918,14 +825,7 @@ private async Task HandleNamedPipeStats(NamedPipeServerStream namedPipeServerStr private async Task HandleNamedPipeTraces(NamedPipeServerStream namedPipeServerStream, CancellationToken cancellationToken) { var request = await MockHttpParser.ReadRequest(namedPipeServerStream); - if (TelemetryEnabled && request.PathAndQuery.StartsWith("/" + TelemetryConstants.AgentTelemetryEndpoint)) - { - HandlePotentialTelemetryData(request); - } - else - { - HandlePotentialTraces(request); - } + HandlePotentialTraces(request); var responseBytes = GetResponseBytes(body: "{}"); await namedPipeServerStream.WriteAsync(responseBytes, offset: 0, count: responseBytes.Length); diff --git a/tracer/test/Datadog.Trace.TestHelpers/TestHelper.cs b/tracer/test/Datadog.Trace.TestHelpers/TestHelper.cs index fd2fd9a1e..be5f5adac 100644 --- a/tracer/test/Datadog.Trace.TestHelpers/TestHelper.cs +++ b/tracer/test/Datadog.Trace.TestHelpers/TestHelper.cs @@ -16,7 +16,6 @@ using System.Net.NetworkInformation; using System.Threading; using System.Threading.Tasks; -using Datadog.Trace.Configuration; using Datadog.Trace.Propagation; using Xunit; using Xunit.Abstractions; @@ -487,27 +486,6 @@ protected bool ShouldUseInstrumentationVerification() return EnvironmentHelper.IsRunningInAzureDevOps() && EnvironmentHelper.IsScheduledBuild(); } - protected void EnableDirectLogSubmission(int intakePort, string integrationName, string host = "integration_tests") - { - SetEnvironmentVariable(ConfigurationKeys.DirectLogSubmission.Host, host); - SetEnvironmentVariable(ConfigurationKeys.DirectLogSubmission.Url, $"http://127.0.0.1:{intakePort}"); - SetEnvironmentVariable(ConfigurationKeys.DirectLogSubmission.EnabledIntegrations, integrationName); - SetEnvironmentVariable(ConfigurationKeys.SignalFxAccessToken, "DUMMY_KEY_REQUIRED_FOR_DIRECT_SUBMISSION"); - } - - protected void EnableTelemetry(bool enabled = true, int? standaloneAgentPort = null) - { - SetEnvironmentVariable("SIGNALFX_INSTRUMENTATION_TELEMETRY_ENABLED", enabled.ToString()); - SetEnvironmentVariable("SIGNALFX_INSTRUMENTATION_TELEMETRY_AGENTLESS_ENABLED", standaloneAgentPort.HasValue.ToString()); - - if (standaloneAgentPort.HasValue) - { - SetEnvironmentVariable("SIGNALFX_INSTRUMENTATION_TELEMETRY_URL", $"http://localhost:{standaloneAgentPort}"); - // API key is required for agentless - SetEnvironmentVariable("SIGNALFX_API_KEY", "INVALID_KEY_FOR_TESTS"); - } - } - protected async Task> GetWebServerSpans( string path, MockTracerAgent agent, diff --git a/tracer/test/Datadog.Trace.Tests/Datadog.Trace.Tests.csproj b/tracer/test/Datadog.Trace.Tests/Datadog.Trace.Tests.csproj index 8d3b15707..2be76d21d 100644 --- a/tracer/test/Datadog.Trace.Tests/Datadog.Trace.Tests.csproj +++ b/tracer/test/Datadog.Trace.Tests/Datadog.Trace.Tests.csproj @@ -57,6 +57,5 @@ - diff --git a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/DirectLogSubmissionSettingsTests.cs b/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/DirectLogSubmissionSettingsTests.cs deleted file mode 100644 index 6fce69af7..000000000 --- a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/DirectLogSubmissionSettingsTests.cs +++ /dev/null @@ -1,101 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Collections.Generic; -using Datadog.Trace.Configuration; -using FluentAssertions; -using Xunit; - -namespace Datadog.Trace.Tests.Logging.DirectSubmission -{ - public class DirectLogSubmissionSettingsTests - { - [Theory] - [InlineData(null)] - [InlineData("")] - [InlineData("somethingelse.com")] - public void WhenDirectLogSubmissionUrlIsProvided_UseIt(string ddSite) - { - var expected = "http://some_url.com"; - var tracerSettings = new TracerSettings(new NameValueConfigurationSource(new() - { - { ConfigurationKeys.DirectLogSubmission.Url, expected }, - { ConfigurationKeys.Site, ddSite }, - })); - - tracerSettings.LogSubmissionSettings.DirectLogSubmissionUrl.Should().Be(expected); - } - - [Theory] - [InlineData(null)] - [InlineData("")] - public void WhenUrlIsNotProvided_AndSiteIsProvided_UsesIt(string url) - { - var domain = "my-domain.net"; - var expected = "https://http-intake.logs.my-domain.net:443"; - var tracerSettings = new TracerSettings(new NameValueConfigurationSource(new() - { - { ConfigurationKeys.DirectLogSubmission.Url, url }, - { ConfigurationKeys.Site, domain }, - })); - - tracerSettings.LogSubmissionSettings.DirectLogSubmissionUrl.Should().Be(expected); - } - - [Fact] - public void WhenNeitherSiteOrUrlAreProvided_UsesDefault() - { - var expected = "https://http-intake.logs.datadoghq.com:443"; - var tracerSettings = new TracerSettings(new NameValueConfigurationSource(new())); - - tracerSettings.LogSubmissionSettings.DirectLogSubmissionUrl.Should().Be(expected); - } - - [Fact] - public void LogSpecificGlobalTagsFallBackToTracerGlobalTags() - { - var expected = new Dictionary { { "test1", "value1" }, { "test2", "value2" }, }; - - var tracerSettings = new TracerSettings(new NameValueConfigurationSource(new() - { - { ConfigurationKeys.GlobalTags, "test1:value1, test2:value2" }, - })); - - tracerSettings.LogSubmissionSettings.DirectLogSubmissionGlobalTags - .Should() - .BeEquivalentTo(expected); - } - - [Fact] - public void LogSpecificGlobalTagsOverrideTracerGlobalTags() - { - var expected = new Dictionary { { "test1", "value1" }, { "test2", "value2" }, }; - - var tracerSettings = new TracerSettings(new NameValueConfigurationSource(new() - { - { ConfigurationKeys.DirectLogSubmission.GlobalTags, "test1:value1, test2:value2" }, - { ConfigurationKeys.GlobalTags, "test3:value3, test4:value4" }, - })); - - tracerSettings.LogSubmissionSettings.DirectLogSubmissionGlobalTags - .Should() - .BeEquivalentTo(expected); - } - - [Fact] - public void LogSpecificGlobalTagsOverrideTracerGlobalTagsEvenWhenEmpty() - { - var tracerSettings = new TracerSettings(new NameValueConfigurationSource(new() - { - { ConfigurationKeys.DirectLogSubmission.GlobalTags, string.Empty }, - { ConfigurationKeys.GlobalTags, "test3:value3, test4:value4" }, - })); - - tracerSettings.LogSubmissionSettings.DirectLogSubmissionGlobalTags - .Should() - .BeEmpty(); - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/DirectSubmissionLogLevelExtensionsTests.cs b/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/DirectSubmissionLogLevelExtensionsTests.cs deleted file mode 100644 index 8035bfbd9..000000000 --- a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/DirectSubmissionLogLevelExtensionsTests.cs +++ /dev/null @@ -1,72 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Linq; -using Datadog.Trace.Logging.DirectSubmission; -using FluentAssertions; -using Xunit; - -namespace Datadog.Trace.Tests.Logging.DirectSubmission -{ - public class DirectSubmissionLogLevelExtensionsTests - { - [Fact] - public void GetName_IsValidForAllLevels() - { - var allValues = Enum.GetValues(typeof(DirectSubmissionLogLevel)) - .Cast(); - - foreach (var value in allValues) - { - value.GetName().Should().NotBeNullOrEmpty(); - } - } - - [Fact] - public void GetName_HandlesUnknownLogLevels() - { - ((DirectSubmissionLogLevel)123).GetName().Should().Be("UNKNOWN"); - } - - [Fact] - public void Parse_IsValidForAllValidValues() - { - var allValues = Enum.GetValues(typeof(DirectSubmissionLogLevel)) - .Cast(); - - foreach (var value in allValues) - { - var parsed = DirectSubmissionLogLevelExtensions.Parse(value.ToString(), defaultLevel: (DirectSubmissionLogLevel)123); - parsed.Should().Be(value); - } - } - - [Theory] - [InlineData("TRACE")] - [InlineData("Trace")] - [InlineData("trace")] - [InlineData("Verbose")] - [InlineData("verbose")] - public void Parse_ReturnsExpectedForKnownValues(string value) - { - var defaultValue = (DirectSubmissionLogLevel)123; - var parsed = DirectSubmissionLogLevelExtensions.Parse(value, defaultValue); - parsed.Should().Be(DirectSubmissionLogLevel.Verbose); - } - - [Theory] - [InlineData("")] - [InlineData(null)] - [InlineData("INVALID")] - [InlineData("NOT_A_LEVEL")] - public void Parse_ReturnsDefaultForUnknownValues(string value) - { - var defaultValue = (DirectSubmissionLogLevel)123; - var parsed = DirectSubmissionLogLevelExtensions.Parse(value, defaultValue); - parsed.Should().Be(defaultValue); - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Formatting/EventIdHashTests.cs b/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Formatting/EventIdHashTests.cs deleted file mode 100644 index ab4f2ec5d..000000000 --- a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Formatting/EventIdHashTests.cs +++ /dev/null @@ -1,30 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -// based on https://github.com/serilog/serilog-formatting-compact/blob/8393e0ab8c2bc746fc733a4f20731b9e1f20f811/test/Serilog.Formatting.Compact.Tests/EventIdHashTests.cs - -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Xunit; - -namespace Datadog.Trace.Tests.Logging.DirectSubmission.Formatting -{ - public class EventIdHashTests - { - [Fact] - public void HashingIsConsistent() - { - var h1 = EventIdHash.Compute("Template 1"); - var h2 = EventIdHash.Compute("Template 1"); - Assert.Equal(h1, h2); - } - - [Fact] - public void DistinctHashesAreComputed() - { - var h1 = EventIdHash.Compute("Template 1"); - var h2 = EventIdHash.Compute("Template 2"); - Assert.NotEqual(h1, h2); - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Formatting/LogFormatterTests.cs b/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Formatting/LogFormatterTests.cs deleted file mode 100644 index 9dc164fc9..000000000 --- a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Formatting/LogFormatterTests.cs +++ /dev/null @@ -1,221 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Datadog.Trace.Configuration; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink.PeriodicBatching; -using Datadog.Trace.Vendors.Newtonsoft.Json; -using FluentAssertions; -using FluentAssertions.Execution; -using Xunit; - -namespace Datadog.Trace.Tests.Logging.DirectSubmission.Formatting -{ - public class LogFormatterTests : IDisposable - { - private const string Host = "the_host"; - private const string Source = "csharp"; - private const string Service = "TestService"; - private const string Env = "integrationTests"; - private const string Version = "1.0.0"; - private readonly LogFormatter _formatter; - private readonly JsonTextWriter _writer; - private readonly StringBuilder _sb; - - public LogFormatterTests() - { - var settings = ImmutableDirectLogSubmissionSettings.Create( - host: Host, - source: Source, - intakeUrl: "http://localhost", - accessToken: "some_value", - minimumLevel: DirectSubmissionLogLevel.Debug, - globalTags: new Dictionary { { "Key1", "Value1" }, { "Key2", "Value2" } }, - enabledLogShippingIntegrations: new List { nameof(IntegrationId.ILogger) }, - batchingOptions: new BatchingSinkOptions(batchSizeLimit: 100, queueLimit: 1000, TimeSpan.FromSeconds(2))); - settings.IsEnabled.Should().BeTrue(); - - _formatter = new LogFormatter( - settings, - serviceName: Service, - env: Env, - version: Version); - - _sb = new StringBuilder(); - _writer = LogFormatter.GetJsonWriter(_sb); - } - - public void Dispose() - { - ((IDisposable)_writer)?.Dispose(); - } - - [Theory] - [InlineData("name", "\"name\":")] - [InlineData("@name", "\"@@name\":")] - [InlineData("@", "\"@@\":")] - public void EscapesPropertyNames(string property, string expected) - { - LogFormatter.WritePropertyName(_writer, property); - _sb.ToString().Should().Be(expected); - } - - [Theory] - [InlineData(null, "null")] - [InlineData("some string", "\"some string\"")] - [InlineData(1234, "1234")] - [InlineData(1234L, "1234")] - [InlineData(1234UL, "1234")] - [InlineData(123.50D, "123.5")] - [InlineData(123.50F, "123.5")] - [InlineData('c', "\"c\"")] - public void WritesValueCorrectly(object value, string expected) - { - LogFormatter.WriteValue(_writer, value); - _sb.ToString().Should().Be(expected); - } - - [Fact] - public void WritesDecimalValueCorrectly() - { - var value = 123.5M; - LogFormatter.WriteValue(_writer, value); - _sb.ToString().Should().Be("123.5"); - } - - [Fact] - public void WritesDateValueCorrectly() - { - var value = new DateTime(year: 2020, month: 3, day: 7, hour: 11, minute: 23, second: 26, millisecond: 500, DateTimeKind.Utc); - LogFormatter.WriteValue(_writer, value); - _sb.ToString().Should().Be("\"2020-03-07T11:23:26.5Z\""); - } - - [Fact] - public void WritesDateTimeOffsetValueCorrectly() - { - var value = new DateTimeOffset(year: 2020, month: 3, day: 7, hour: 11, minute: 23, second: 26, millisecond: 500, offset: TimeSpan.Zero); - LogFormatter.WriteValue(_writer, value); - _sb.ToString().Should().Be("\"2020-03-07T11:23:26.5+00:00\""); - } - - [Fact] - public void WritesTimespanCorrectly() - { - var value = TimeSpan.FromSeconds(100); - LogFormatter.WriteValue(_writer, value); - _sb.ToString().Should().Be("\"00:01:40\""); - } - - [Fact] - public void WritesFormattableObjectCorrectly() - { - var value = new FormattableObject { SomeValue = "testing!" }; - LogFormatter.WriteValue(_writer, value); - _sb.ToString().Should().Be("\"SomeValue = testing!\""); - } - - [Fact] - public void WritesObjectCorrectly() - { - var value = new TestObject { SomeValue = "testing!" }; - LogFormatter.WriteValue(_writer, value); - _sb.ToString().Should().Be("\"Datadog.Trace.Tests.Logging.DirectSubmission.Formatting.LogFormatterTests+TestObject\""); - } - - [Theory] - [MemberData(nameof(TestData.AllOptions), MemberType = typeof(TestData))] - public void WritesLogFormatCorrectly( - bool hasRenderedSource, - bool hasRenderedService, - bool hasRenderedHost, - bool hasRenderedTags, - bool hasRenderedEnv, - bool hasRenderedVersion) - { - var timestamp = new DateTime(year: 2020, month: 3, day: 7, hour: 11, minute: 23, second: 26, millisecond: 500, DateTimeKind.Utc); - var sb = new StringBuilder(); - var state = new TestObject(); - var message = "Some message"; - var logLevel = "Info"; - - _formatter.FormatLog(sb, state, timestamp, message, eventId: null, logLevel, exception: null, RenderProperties); - - var log = sb.ToString(); - - log - .Should() - .Contain(timestamp.ToString("o")) - .And.Contain(message) - .And.Contain(logLevel); - - using var scope = new AssertionScope(); - HasExpectedValue(log, !hasRenderedSource, $"\"ddsource\":\"{Source}\""); - HasExpectedValue(log, !hasRenderedService, $"\"service\":\"{Service}\""); - HasExpectedValue(log, !hasRenderedHost, $"\"host\":\"{Host}\""); - HasExpectedValue(log, !hasRenderedTags, $"\"ddtags\":\"Key1:Value1,Key2:Value2\""); - HasExpectedValue(log, !hasRenderedEnv, $"\"dd_env\":\"{Env}\""); - HasExpectedValue(log, !hasRenderedVersion, $"\"dd_version\":\"{Version}\""); - - LogPropertyRenderingDetails RenderProperties(JsonTextWriter jsonTextWriter, in TestObject o) => - new LogPropertyRenderingDetails( - hasRenderedSource: hasRenderedSource, - hasRenderedService: hasRenderedService, - hasRenderedHost: hasRenderedHost, - hasRenderedTags: hasRenderedTags, - hasRenderedEnv: hasRenderedEnv, - hasRenderedVersion: hasRenderedVersion, - messageTemplate: null); - - static void HasExpectedValue(string log, bool shouldContain, string value) - { - if (shouldContain) - { - log.Should().Contain(value); - } - else - { - log.Should().NotContain(value); - } - } - } - - private class TestData - { - private static readonly bool[] Options = { true, false }; - - public static IEnumerable AllOptions - => from src in Options - from service in Options - from host in Options - from tags in Options - from env in Options - from version in Options - select new object[] { src, service, host, tags, env, version }; - } - - private class FormattableObject : IFormattable - { - public string SomeValue { get; set; } - - public string ToString(string format, IFormatProvider formatProvider) - { - return "SomeValue = " + SomeValue; - } - } - - private class TestObject - { - public string SomeValue { get; set; } - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/ImmutableDirectLogSubmissionSettingsTests.cs b/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/ImmutableDirectLogSubmissionSettingsTests.cs deleted file mode 100644 index 81ec4a2ad..000000000 --- a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/ImmutableDirectLogSubmissionSettingsTests.cs +++ /dev/null @@ -1,245 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System.Collections.Generic; -using System.Collections.Specialized; -using System.Linq; -using Datadog.Trace.Configuration; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.TestHelpers; -using FluentAssertions; -using FluentAssertions.Execution; -using Xunit; - -namespace Datadog.Trace.Tests.Logging.DirectSubmission -{ - public class ImmutableDirectLogSubmissionSettingsTests - { - private static readonly List AllIntegrations = - ImmutableDirectLogSubmissionSettings.SupportedIntegrations.Select(x => x.ToString()).ToList(); - - private static readonly NameValueCollection Defaults = new() - { - { ConfigurationKeys.LogsInjectionEnabled, "1" }, - { ConfigurationKeys.SignalFxAccessToken, "some_key" }, - { ConfigurationKeys.DirectLogSubmission.Host, "integration_tests" }, - { ConfigurationKeys.DirectLogSubmission.EnabledIntegrations, string.Join(";", AllIntegrations) }, - }; - - [Fact] - public void ValidSettingsAreValid() - { - var settings = LogSettingsHelper.GetValidSettings(); - settings.IsEnabled.Should().BeTrue(); - } - - [Fact] - public void ValidDefaultsAreValid() - { - var tracerSettings = new TracerSettings(new NameValueConfigurationSource(Defaults)); - var logSettings = ImmutableDirectLogSubmissionSettings.Create(tracerSettings); - - logSettings.IsEnabled.Should().BeTrue(); - logSettings.ValidationErrors.Should().BeEmpty(); - } - - [Theory] - [InlineData("")] - [InlineData(" ")] - [InlineData(null)] - public void InvalidApiKeyIsInvalid(string accessToken) - { - var tracerSettings = new TracerSettings(new NameValueConfigurationSource(Defaults)); - tracerSettings.LogSubmissionSettings.SignalFxAccessToken = accessToken; - var logSettings = ImmutableDirectLogSubmissionSettings.Create(tracerSettings); - - logSettings.IsEnabled.Should().BeFalse(); - logSettings.ValidationErrors.Should().NotBeEmpty(); - } - - [Theory] - [InlineData("VeryVerbose", DirectSubmissionLogLevel.Information)] - [InlineData("", DirectSubmissionLogLevel.Information)] - [InlineData(null, DirectSubmissionLogLevel.Information)] - [InlineData("Verbose", DirectSubmissionLogLevel.Verbose)] - [InlineData("trace", DirectSubmissionLogLevel.Verbose)] - [InlineData("Debug", DirectSubmissionLogLevel.Debug)] - [InlineData("Info", DirectSubmissionLogLevel.Information)] - [InlineData("Warning", DirectSubmissionLogLevel.Warning)] - [InlineData("ERROR", DirectSubmissionLogLevel.Error)] - [InlineData("Fatal", DirectSubmissionLogLevel.Fatal)] - [InlineData("critical", DirectSubmissionLogLevel.Fatal)] - public void ParsesLogLevelsCorrectly(string value, DirectSubmissionLogLevel expected) - { - var updatedSettings = new NameValueCollection(Defaults); - updatedSettings[ConfigurationKeys.DirectLogSubmission.MinimumLevel] = value; - var tracerSettings = new TracerSettings(new NameValueConfigurationSource(updatedSettings)); - var logSettings = ImmutableDirectLogSubmissionSettings.Create(tracerSettings); - - logSettings.IsEnabled.Should().BeTrue(); - logSettings.ValidationErrors.Should().BeEmpty(); - logSettings.MinimumLevel.Should().Be(expected); - } - - [Theory] - [InlineData(ConfigurationKeys.DirectLogSubmission.Host, "")] - [InlineData(ConfigurationKeys.DirectLogSubmission.Host, " ")] - [InlineData(ConfigurationKeys.DirectLogSubmission.Source, "")] - [InlineData(ConfigurationKeys.DirectLogSubmission.Source, " ")] - [InlineData(ConfigurationKeys.DirectLogSubmission.Url, " ")] - [InlineData(ConfigurationKeys.DirectLogSubmission.Url, "localhost")] - public void InvalidSettingDisablesDirectLogSubmission(string setting, string value) - { - var updatedSettings = new NameValueCollection(Defaults); - updatedSettings[setting] = value; - - var tracerSettings = new TracerSettings(new NameValueConfigurationSource(updatedSettings)); - var logSettings = ImmutableDirectLogSubmissionSettings.Create(tracerSettings); - - logSettings.IsEnabled.Should().BeFalse(); - logSettings.ValidationErrors.Should().NotBeEmpty(); - } - - [Theory] - [InlineData(ConfigurationKeys.DirectLogSubmission.EnabledIntegrations, "Garbage")] - public void InvalidSettingWarnsButDoesNotDisableDirectLogSubmission(string setting, string value) - { - var updatedSettings = new NameValueCollection(Defaults); - updatedSettings[setting] = value; - - var tracerSettings = new TracerSettings(new NameValueConfigurationSource(updatedSettings)); - var logSettings = ImmutableDirectLogSubmissionSettings.Create(tracerSettings); - - logSettings.IsEnabled.Should().BeTrue(); - logSettings.ValidationErrors.Should().NotBeEmpty(); - } - - [Fact] - public void CanLoadSettingsFromTracerSettings() - { - var apiKey = "some_key"; - var hostName = "integration_tests"; - var intake = "http://localhost:1234"; - var enabledIntegrations = ImmutableDirectLogSubmissionSettings.SupportedIntegrations - .Select(x => x.ToString()) - .ToList(); - - var collection = new NameValueCollection - { - { ConfigurationKeys.LogsInjectionEnabled, "1" }, - { ConfigurationKeys.SignalFxAccessToken, apiKey }, - { ConfigurationKeys.DirectLogSubmission.Host, hostName }, - { ConfigurationKeys.DirectLogSubmission.Url, intake }, - { ConfigurationKeys.DirectLogSubmission.EnabledIntegrations, string.Join(";", enabledIntegrations) }, - { ConfigurationKeys.DirectLogSubmission.GlobalTags, "sometag:value, someothertag:someothervalue" }, - }; - - IConfigurationSource source = new NameValueConfigurationSource(collection); - var tracerSettings = new TracerSettings(source); - - var logSettings = ImmutableDirectLogSubmissionSettings.Create(tracerSettings); - - using var scope = new AssertionScope(); - logSettings.ApiKey.Should().Be(apiKey); - logSettings.Host.Should().Be(hostName); - logSettings.IntakeUrl?.ToString().Should().Be("http://localhost:1234/"); - logSettings.GlobalTags.Should().BeOneOf("someothertag:someothervalue,sometag:value", "sometag:value,someothertag:someothervalue"); - logSettings.IsEnabled.Should().BeTrue(); - logSettings.MinimumLevel.Should().Be(DirectSubmissionLogLevel.Information); - logSettings.Source.Should().Be("csharp"); - logSettings.ValidationErrors.Should().BeEmpty(); - logSettings.EnabledIntegrationNames.Should().Equal(enabledIntegrations); - } - - [Theory] - [InlineData("nlog")] - [InlineData("NLOG")] - [InlineData("nLog")] - [InlineData("Nlog")] - [InlineData("NLog")] - [InlineData("nLog;nlog;Nlog")] - public void EnabledIntegrationsAreCaseInsensitive(string integration) - { - var config = new NameValueCollection(Defaults); - config[ConfigurationKeys.DirectLogSubmission.EnabledIntegrations] = integration; - - var tracerSettings = new TracerSettings(new NameValueConfigurationSource(config)); - var logSettings = ImmutableDirectLogSubmissionSettings.Create(tracerSettings); - - logSettings.IsEnabled.Should().BeTrue(); - logSettings.ValidationErrors.Should().BeEmpty(); - var expected = new List { nameof(IntegrationId.NLog) }; - logSettings.EnabledIntegrationNames.Should().BeEquivalentTo(expected); - } - - [Theory] - [InlineData(false, false)] - [InlineData(false, true)] - [InlineData(true, false)] - [InlineData(true, true)] - public void WhenLogsInjectionIsExplicitlySetViaEnvironmentThenValueIsUsed(bool logsInjectionEnabled, bool directLogSubmissionEnabled) - { - var config = new NameValueCollection(Defaults); - config[ConfigurationKeys.LogsInjectionEnabled] = logsInjectionEnabled.ToString(); - - if (!directLogSubmissionEnabled) - { - config.Remove(ConfigurationKeys.DirectLogSubmission.EnabledIntegrations); - } - - var tracerSettings = new TracerSettings(new NameValueConfigurationSource(config)); - var immutableSettings = new ImmutableTracerSettings(tracerSettings); - - immutableSettings.LogSubmissionSettings.IsEnabled.Should().Be(directLogSubmissionEnabled); - immutableSettings.LogsInjectionEnabled.Should().Be(logsInjectionEnabled); - } - - [Theory] - [InlineData(false, false)] - [InlineData(false, true)] - [InlineData(true, false)] - [InlineData(true, true)] - public void WhenLogsInjectionIsExplicitlySetViaCodeThenValueIsUsed(bool logsInjectionEnabled, bool directLogSubmissionEnabled) - { - var config = new NameValueCollection(Defaults); - config.Remove(ConfigurationKeys.LogsInjectionEnabled); - - if (!directLogSubmissionEnabled) - { - config.Remove(ConfigurationKeys.DirectLogSubmission.EnabledIntegrations); - } - - var tracerSettings = new TracerSettings(new NameValueConfigurationSource(config)); - tracerSettings.LogsInjectionEnabled = logsInjectionEnabled; - - var immutableSettings = new ImmutableTracerSettings(tracerSettings); - - immutableSettings.LogSubmissionSettings.IsEnabled.Should().Be(directLogSubmissionEnabled); - immutableSettings.LogsInjectionEnabled.Should().Be(logsInjectionEnabled); - } - - [Theory] - [InlineData(true)] - [InlineData(false)] - public void WhenLogsInjectionIsNotSetThenValueIsSameAsLogSubmissionEnabled(bool directLogSubmissionEnabled) - { - var config = new NameValueCollection(Defaults); - config.Remove(ConfigurationKeys.LogsInjectionEnabled); - - if (!directLogSubmissionEnabled) - { - config.Remove(ConfigurationKeys.DirectLogSubmission.EnabledIntegrations); - } - - var tracerSettings = new TracerSettings(new NameValueConfigurationSource(config)); - var immutableSettings = new ImmutableTracerSettings(tracerSettings); - - immutableSettings.LogSubmissionSettings.IsEnabled.Should().Be(directLogSubmissionEnabled); - immutableSettings.LogsInjectionEnabled.Should().Be(directLogSubmissionEnabled); - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/DatadogSinkTests.cs b/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/DatadogSinkTests.cs deleted file mode 100644 index f134d0a4b..000000000 --- a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/DatadogSinkTests.cs +++ /dev/null @@ -1,284 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink; -using Datadog.Trace.Logging.DirectSubmission.Sink.PeriodicBatching; -using Datadog.Trace.TestHelpers; -using FluentAssertions; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using Xunit; - -namespace Datadog.Trace.Tests.Logging.DirectSubmission.Sink -{ - public class DatadogSinkTests - { - private const int DefaultQueueLimit = 100_000; - private static readonly TimeSpan TinyWait = TimeSpan.FromMilliseconds(50); - - [Fact] - public void SinkSendsMessagesToLogsApi() - { - var mutex = new ManualResetEventSlim(); - - var logsApi = new TestLogsApi(_ => - { - mutex.Set(); - return true; - }); - var options = new BatchingSinkOptions(batchSizeLimit: 2, queueLimit: DefaultQueueLimit, period: TinyWait); - var sink = new DatadogSink(logsApi, LogSettingsHelper.GetFormatter(), options); - sink.Start(); - - sink.EnqueueLog(new TestLogEvent(DirectSubmissionLogLevel.Debug, "First message")); - - // Wait for the logs to be sent, should be done in 50ms - mutex.Wait(TimeSpan.FromSeconds(10)).Should().BeTrue(); - logsApi.Logs.Should().ContainSingle(); - } - - [Fact] - public void SinkRejectsGiantMessages() - { - var mutex = new ManualResetEventSlim(); - - var logsApi = new TestLogsApi(); - var options = new BatchingSinkOptions(batchSizeLimit: 2, queueLimit: DefaultQueueLimit, period: TinyWait); - var sink = new DatadogSink( - logsApi, - LogSettingsHelper.GetFormatter(), - options, - oversizeLogCallback: _ => mutex.Set(), - sinkDisabledCallback: () => { }); - sink.Start(); - - var message = new StringBuilder().Append('x', repeatCount: 1024 * 1024).ToString(); - sink.EnqueueLog(new TestLogEvent(DirectSubmissionLogLevel.Debug, message)); - - // Wait for the logs to be sent, should be done in 50ms - mutex.Wait(TimeSpan.FromSeconds(10)).Should().BeTrue(); - logsApi.Logs.Should().BeEmpty(); - } - - [Fact] - public void SinkSendsMessageAsJsonBatch() - { - var mutex = new ManualResetEventSlim(); - int logsReceived = 0; - const int expectedCount = 2; - - bool LogsSentCallback(int x) - { - if (Interlocked.Add(ref logsReceived, x) == expectedCount) - { - mutex.Set(); - } - - return true; - } - - var logsApi = new TestLogsApi(LogsSentCallback); - var options = new BatchingSinkOptions(batchSizeLimit: 2, queueLimit: DefaultQueueLimit, period: TinyWait); - var sink = new DatadogSink(logsApi, LogSettingsHelper.GetFormatter(), options); - sink.Start(); - - var firstMessage = "First message"; - var secondMessage = "Second message"; - sink.EnqueueLog(new TestLogEvent(DirectSubmissionLogLevel.Debug, firstMessage)); - sink.EnqueueLog(new TestLogEvent(DirectSubmissionLogLevel.Information, secondMessage)); - - mutex.Wait(TimeSpan.FromSeconds(10)).Should().BeTrue(); - logsApi.Logs.Should().NotBeEmpty(); - - var logs = logsApi.Logs - .Select(batch => Encoding.UTF8.GetString(batch.Logs.Array)) - .SelectMany(batch => JsonConvert.DeserializeObject>(batch)) - .ToList(); - - logs.Should().NotBeNull(); - logs.Count.Should().Be(2); - logs[0].Level.Should().Be(DirectSubmissionLogLevel.Debug); - logs[0].Message.Should().Be(firstMessage); - logs[1].Level.Should().Be(DirectSubmissionLogLevel.Information); - logs[1].Message.Should().Be(secondMessage); - } - - [Fact] - public void SinkSendsMultipleBatches() - { - var mutex = new ManualResetEventSlim(); - int logsReceived = 0; - const int expectedCount = 5; - - bool LogsSentCallback(int x) - { - if (Interlocked.Add(ref logsReceived, x) == expectedCount) - { - mutex.Set(); - } - - return true; - } - - var logsApi = new TestLogsApi(LogsSentCallback); - var options = new BatchingSinkOptions(batchSizeLimit: 2, queueLimit: DefaultQueueLimit, period: TinyWait); - var sink = new DatadogSink(logsApi, LogSettingsHelper.GetFormatter(), options); - sink.Start(); - - sink.EnqueueLog(new TestLogEvent(DirectSubmissionLogLevel.Debug, "First message")); - sink.EnqueueLog(new TestLogEvent(DirectSubmissionLogLevel.Information, "Second message")); - sink.EnqueueLog(new TestLogEvent(DirectSubmissionLogLevel.Information, "Third message")); - sink.EnqueueLog(new TestLogEvent(DirectSubmissionLogLevel.Information, "Fourth message")); - sink.EnqueueLog(new TestLogEvent(DirectSubmissionLogLevel.Information, "Fifth message")); - - mutex.Wait(TimeSpan.FromSeconds(10)).Should().BeTrue(); - - logsApi.Logs.Should().HaveCountGreaterOrEqualTo(3); // batch size is 2, so at least 3 batches - - var logs = logsApi.Logs - .Select(batch => Encoding.UTF8.GetString(batch.Logs.Array)) - .SelectMany(batch => JsonConvert.DeserializeObject>(batch)) - .ToList(); - - logs.Count.Should().Be(5); - logs.Select(x => x.Message).Should().OnlyHaveUniqueItems(); - } - - [Theory] - [InlineData(true)] - [InlineData(false)] - public async Task EmitBatchEchoesLogsApiReturnValue(bool logsApiResponse) - { - var mutex = new ManualResetEventSlim(); - bool LogsSentCallback(int x) - { - mutex.Set(); - - return logsApiResponse; - } - - var logsApi = new TestLogsApi(LogsSentCallback); - var options = new BatchingSinkOptions(batchSizeLimit: 2, queueLimit: DefaultQueueLimit, period: TinyWait); - var sink = new TestSink(logsApi, LogSettingsHelper.GetFormatter(), options); - sink.Start(); - var log = new TestLogEvent(DirectSubmissionLogLevel.Debug, "First message"); - var queue = new Queue(); - queue.Enqueue(log); - - var result = await sink.CallEmitBatch(queue); - - result.Should().Be(logsApiResponse); - } - - [Fact] - public void IfCircuitBreakerBreaksThenNoApiRequestsAreSent() - { - var mutex = new ManualResetEventSlim(); - int logsReceived = 0; - - bool LogsSentCallback(int x) - { - Interlocked.Add(ref logsReceived, x); - mutex.Set(); - return false; - } - - var logsApi = new TestLogsApi(LogsSentCallback); - var options = new BatchingSinkOptions(batchSizeLimit: 2, queueLimit: DefaultQueueLimit, period: TinyWait); - var sink = new DatadogSink(logsApi, LogSettingsHelper.GetFormatter(), options); - sink.Start(); - - for (var i = 0; i < BatchingSink.FailuresBeforeCircuitBreak; i++) - { - sink.EnqueueLog(new TestLogEvent(DirectSubmissionLogLevel.Debug, "A message")); - mutex.Wait(10_000).Should().BeTrue(); - mutex.Reset(); - } - - // circuit should be broken - sink.EnqueueLog(new TestLogEvent(DirectSubmissionLogLevel.Debug, "A message")); - mutex.Wait(3_000).Should().BeFalse(); // don't expect it to be set - - logsReceived.Should().Be(BatchingSink.FailuresBeforeCircuitBreak); - } - - internal class TestLogEvent : DatadogLogEvent - { - public TestLogEvent(DirectSubmissionLogLevel level, string message) - { - Level = level; - Message = message; - } - - [JsonConverter(typeof(StringEnumConverter))] - public DirectSubmissionLogLevel Level { get; } - - public string Message { get; } - - public override void Format(StringBuilder sb, LogFormatter formatter) - { - sb.Append(JsonConvert.SerializeObject(this)); - } - } - - internal class TestLogsApi : ILogsApi - { - private readonly Func _logsSentCallback; - - public TestLogsApi(Func logsSentCallback = null) - { - _logsSentCallback = logsSentCallback; - } - - public Queue Logs { get; } = new(); - - public void Dispose() - { - } - - public Task SendLogsAsync(ArraySegment logs, int numberOfLogs) - { - // create a copy of it - Logs.Enqueue(new SentMessage(new ArraySegment(logs.ToArray()), numberOfLogs)); - var result = _logsSentCallback?.Invoke(numberOfLogs) ?? true; - return Task.FromResult(result); - } - } - - internal class SentMessage - { - public SentMessage(ArraySegment logs, int numberOfLogs) - { - Logs = logs; - NumberOfLogs = numberOfLogs; - } - - public ArraySegment Logs { get; } - - public int NumberOfLogs { get; } - } - - internal class TestSink : DatadogSink - { - public TestSink(ILogsApi api, LogFormatter formatter, BatchingSinkOptions sinkOptions) - : base(api, formatter, sinkOptions) - { - } - - public Task CallEmitBatch(Queue events) - { - return EmitBatch(events); - } - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/LogsApiTests.cs b/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/LogsApiTests.cs deleted file mode 100644 index b0c9578c7..000000000 --- a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/LogsApiTests.cs +++ /dev/null @@ -1,226 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading.Tasks; -using Datadog.Trace.Agent; -using Datadog.Trace.Logging.DirectSubmission.Sink; -using Datadog.Trace.Util; -using FluentAssertions; -using FluentAssertions.Execution; -using Xunit; - -namespace Datadog.Trace.Tests.Logging.DirectSubmission.Sink -{ - public class LogsApiTests - { - private const string DefaultIntake = "https://http-intake.logs.datadoghq.com:443"; - private const int NumberOfLogs = 1; - private static readonly ArraySegment Logs = new( - Encoding.UTF8.GetBytes("{\"Level\":\"Debug\",\"Message\":\"Well done, you sent a message\"}")); - - private static readonly Func SingleFaultyRequest = x => new FaultyApiRequest(x); - - [Theory] - [InlineData("http://http-intake.logs.datadoghq.com", "http://http-intake.logs.datadoghq.com/api/v2/logs")] - [InlineData("http://http-intake.logs.datadoghq.com/", "http://http-intake.logs.datadoghq.com/api/v2/logs")] - [InlineData("https://http-intake.logs.datadoghq.com:443", "https://http-intake.logs.datadoghq.com:443/api/v2/logs")] - [InlineData("http://localhost:8080", "http://localhost:8080/api/v2/logs")] - [InlineData("http://localhost:8080/sub-path", "http://localhost:8080/sub-path/api/v2/logs")] - [InlineData("http://localhost:8080/sub-path/", "http://localhost:8080/sub-path/api/v2/logs")] - public async Task SendsRequestToCorrectUrl(string baseUri, string expected) - { - var baseEndpoint = new Uri(baseUri); - var requestFactory = new TestRequestFactory(baseEndpoint); - - var api = new LogsApi("SECR3TZ", requestFactory); - var result = await api.SendLogsAsync(Logs, NumberOfLogs); - - requestFactory.RequestsSent.Should() - .OnlyContain(x => x.Endpoint == new Uri(expected)); - - result.Should().BeTrue(); - } - - [Fact] - public async Task ShouldRetryRequestsWhenTheyFail() - { - // two faults, then success - var requestFactory = new TestRequestFactory(new Uri(DefaultIntake), SingleFaultyRequest, SingleFaultyRequest); - - var apiKey = "SECR3TZ"; - var api = new LogsApi(apiKey, requestFactory); - var result = await api.SendLogsAsync(Logs, NumberOfLogs); - - requestFactory.RequestsSent - .Where(x => x is FaultyApiRequest) - .Should() - .HaveCount(2); - - requestFactory.RequestsSent - .Where(x => x is not FaultyApiRequest) - .Should() - .HaveCount(1); - result.Should().BeTrue(); - } - - [Fact] - public async Task ShouldAddApiKeyToAllRequests() - { - var requestFactory = new TestRequestFactory(new Uri(DefaultIntake), SingleFaultyRequest); - - var apiKey = "SECR3TZ"; - var api = new LogsApi(apiKey, requestFactory); - await api.SendLogsAsync(Logs, NumberOfLogs); - - requestFactory.RequestsSent.Should() - .NotBeEmpty() - .And.OnlyContain(x => x.ExtraHeaders.ContainsKey(LogsApi.IntakeHeaderNameApiKey)) - .And.OnlyContain(x => x.ExtraHeaders[LogsApi.IntakeHeaderNameApiKey] == apiKey); - } - - [Fact] - public async Task ShouldSetContentTypeForAllRequests() - { - var requestFactory = new TestRequestFactory(new Uri(DefaultIntake), SingleFaultyRequest); - - var api = new LogsApi("SECR3TZ", requestFactory); - await api.SendLogsAsync(Logs, NumberOfLogs); - - using var scope = new AssertionScope(); - requestFactory.RequestsSent.Should().NotBeEmpty(); - foreach (var request in requestFactory.RequestsSent) - { - request.Responses.Should() - .ContainSingle() - .And.OnlyContain(x => x.ContentType == "application/json"); - } - } - - [Fact] - public async Task ShouldNotRetryWhenClientError() - { - var requestFactory = new TestRequestFactory(new Uri(DefaultIntake), x => new FaultyApiRequest(x, statusCode: 400)); - - var api = new LogsApi("SECR3TZ", requestFactory); - var result = await api.SendLogsAsync(Logs, NumberOfLogs); - - using var scope = new AssertionScope(); - var request = requestFactory.RequestsSent.Should().ContainSingle().Subject; - request.Responses.Should().ContainSingle().Which.StatusCode.Should().Be(400); - - result.Should().BeFalse(); - } - - internal class TestRequestFactory : IApiRequestFactory - { - private readonly Uri _baseEndpoint; - private readonly Func[] _requestsToSend; - - public TestRequestFactory(Uri baseEndpoint, params Func[] requestsToSend) - { - _baseEndpoint = baseEndpoint; - _requestsToSend = requestsToSend; - } - - public List RequestsSent { get; } = new(); - - public Uri GetEndpoint(string relativePath) - { - return UriHelpers.Combine(_baseEndpoint, relativePath); - } - - public string Info(Uri endpoint) => endpoint.ToString(); - - public IApiRequest Create(Uri endpoint) - { - var request = (_requestsToSend is null || RequestsSent.Count >= _requestsToSend.Length) - ? new TestApiRequest(endpoint) - : _requestsToSend[RequestsSent.Count](endpoint); - - RequestsSent.Add(request); - - return request; - } - - public void SetProxy(WebProxy proxy, NetworkCredential credential) - { - } - } - - internal class TestApiRequest : IApiRequest - { - private readonly int _statusCode; - - public TestApiRequest(Uri endpoint, int statusCode = 200) - { - _statusCode = statusCode; - Endpoint = endpoint; - } - - public Uri Endpoint { get; } - - public Dictionary ExtraHeaders { get; } = new(); - - public List Responses { get; } = new(); - - public void AddHeader(string name, string value) - { - ExtraHeaders.Add(name, value); - } - - public Task GetAsync() - { - throw new NotImplementedException(); - } - - public Task PostAsync(ArraySegment traces, string contentType) - { - var response = new TestApiResponse(_statusCode, "The message body", contentType); - Responses.Add(response); - - return Task.FromResult((IApiResponse)response); - } - } - - internal class FaultyApiRequest : TestApiRequest - { - public FaultyApiRequest(Uri endpoint, int statusCode = 500) - : base(endpoint, statusCode) - { - } - } - - internal class TestApiResponse : IApiResponse - { - private readonly string _body; - - public TestApiResponse(int statusCode, string body, string contentType) - { - StatusCode = statusCode; - _body = body; - ContentType = contentType; - } - - public string ContentType { get; } - - public int StatusCode { get; } - - public long ContentLength => _body?.Length ?? 0; - - public void Dispose() - { - } - - public string GetHeader(string headerName) => throw new NotImplementedException(); - - public Task ReadAsStringAsync() => Task.FromResult(_body); - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/PeriodicBatching/BatchingSinkTests.cs b/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/PeriodicBatching/BatchingSinkTests.cs deleted file mode 100644 index 15256a176..000000000 --- a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/PeriodicBatching/BatchingSinkTests.cs +++ /dev/null @@ -1,218 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.Logging.DirectSubmission.Sink; -using Datadog.Trace.Logging.DirectSubmission.Sink.PeriodicBatching; -using FluentAssertions; -using Xunit; -using Xunit.Abstractions; - -namespace Datadog.Trace.Tests.Logging.DirectSubmission.Sink.PeriodicBatching -{ - public class BatchingSinkTests - { - private const int DefaultQueueLimit = 100_000; - private static readonly TimeSpan TinyWait = TimeSpan.FromMilliseconds(200); - private static readonly TimeSpan CircuitBreakPeriod = TimeSpan.FromSeconds(1); - - private static readonly BatchingSinkOptions DefaultBatchingOptions - = new(batchSizeLimit: 2, queueLimit: DefaultQueueLimit, period: TinyWait, circuitBreakPeriod: CircuitBreakPeriod); - - private readonly ITestOutputHelper _output; - - public BatchingSinkTests(ITestOutputHelper output) - { - _output = output; - } - - // Some very, very approximate tests here :) - - [Fact] - public async Task WhenRunning_AndAnEventIsQueued_ItIsWrittenToABatchOnDispose() - { - var sink = new InMemoryBatchedSink(DefaultBatchingOptions); - sink.Start(); - var evt = new TestEvent("Some event"); - - sink.EnqueueLog(evt); - await sink.DisposeAsync(); - - sink.Batches.Count.Should().Be(1); - sink.Batches.TryPeek(out var batch).Should().BeTrue(); - batch.Should().BeEquivalentTo(new List { evt }); - } - - [Fact] - public void WhenRunning_AndAnEventIsQueued_ItIsWrittenToABatch() - { - var sink = new InMemoryBatchedSink(DefaultBatchingOptions); - sink.Start(); - var evt = new TestEvent("Some event"); - - sink.EnqueueLog(evt); - var batches = WaitForBatches(sink); - - batches.Count.Should().Be(1); - sink.Batches.TryPeek(out var batch).Should().BeTrue(); - batch.Should().BeEquivalentTo(new List { evt }); - } - - [Fact] - public async Task AfterDisposed_AndAnEventIsQueued_ItIsNotWrittenToABatch() - { - var sink = new InMemoryBatchedSink(DefaultBatchingOptions); - sink.Start(); - var evt = new TestEvent("Some event"); - await sink.DisposeAsync(); - sink.EnqueueLog(evt); - - // slightly arbitrary time to wait - Thread.Sleep(1_000); - sink.Batches.Should().BeEmpty(); - } - - [Fact] - public void AfterMultipleFailures_SinkIsPermanentlyDisabled() - { - var mutex = new ManualResetEventSlim(); - var emitResults = Enumerable.Repeat(false, BatchingSink.FailuresBeforeCircuitBreak); - var sink = new InMemoryBatchedSink( - DefaultBatchingOptions, - () => mutex.Set(), - emitResults.ToArray()); - sink.Start(); - var evt = new TestEvent("Some event"); - - for (var i = 0; i < BatchingSink.FailuresBeforeCircuitBreak; i++) - { - sink.EnqueueLog(evt); - WaitForBatches(sink, batchCount: i + 1); - } - - mutex.Wait(10_000).Should().BeTrue($"Sink should be disabled after {BatchingSink.FailuresBeforeCircuitBreak} faults"); - } - - [Fact] - public async Task SinkDoesNotStartEmittingUntilStartIsCalled() - { - var sink = new InMemoryBatchedSink(DefaultBatchingOptions); - var evt = new TestEvent("Some event"); - sink.EnqueueLog(evt); - - await Task.Delay(5_000); - sink.Batches.Should().BeEmpty(); - - sink.Start(); - var batches = WaitForBatches(sink); - batches.Should().ContainSingle(); - } - - [Fact] - public void AfterInitialSuccessThenMultipleFailures_SinkIsTemporarilyDisabled() - { - var emitResults = new[] { true } - .Concat(Enumerable.Repeat(false, BatchingSink.FailuresBeforeCircuitBreak)); - - var sink = new InMemoryBatchedSink( - DefaultBatchingOptions, - emitResults: emitResults.ToArray()); - sink.Start(); - var evt = new TestEvent("Some event"); - - // Initial success ensures we don't permanently disable the sink - _output.WriteLine("Queueing first event and waiting for sink"); - sink.EnqueueLog(evt); - var batches = WaitForBatches(sink, batchCount: 1); - _output.WriteLine($"Found {batches.Count} batches"); - - // Put the sink in a broken status (temporary) - for (var i = 0; i < BatchingSink.FailuresBeforeCircuitBreak; i++) - { - _output.WriteLine($"Queueing broken event {i + 1}"); - sink.EnqueueLog(evt); - batches = WaitForBatches(sink, batchCount: i + 2); - _output.WriteLine($"Found {batches.Count} batches"); - } - - // initial enqueue should be ignored - _output.WriteLine($"Queueing event when broken circuit"); - sink.EnqueueLog(evt); - Thread.Sleep(CircuitBreakPeriod); - Thread.Sleep(CircuitBreakPeriod); - // ensure we _don't_ have any more batches - sink.Batches.Count.Should().Be(BatchingSink.FailuresBeforeCircuitBreak + 1); - - // queue another log now circuit is partially open - _output.WriteLine($"Queueing event in partially open sink"); - sink.EnqueueLog(evt); - batches = WaitForBatches(sink, batchCount: BatchingSink.FailuresBeforeCircuitBreak + 2); - _output.WriteLine($"Found {batches.Count} batches"); - } - - private static ConcurrentStack> WaitForBatches(InMemoryBatchedSink pbs, int batchCount = 1) - { - var deadline = DateTime.UtcNow.AddSeconds(10); - var batches = pbs.Batches; - while (batches.Count < batchCount && DateTime.UtcNow < deadline) - { - Thread.Sleep(TinyWait); - batches = pbs.Batches; - } - - return batches; - } - - internal class TestEvent : DatadogLogEvent - { - private readonly string _evt; - - public TestEvent(string evt) - { - _evt = evt; - } - - public override void Format(StringBuilder sb, LogFormatter formatter) - { - sb.Append(_evt); - } - } - - private class InMemoryBatchedSink : BatchingSink - { - private readonly bool[] _emitResults; - private int _emitCount = -1; - - public InMemoryBatchedSink( - BatchingSinkOptions sinkOptions, - Action disableSinkAction = null, - bool[] emitResults = null) - : base(sinkOptions, disableSinkAction) - { - _emitResults = emitResults ?? Array.Empty(); - } - - public ConcurrentStack> Batches { get; } = new(); - - protected override Task EmitBatch(Queue events) - { - Batches.Push(events.ToList()); - _emitCount++; - var result = _emitCount < _emitResults.Length - ? _emitResults[_emitCount] - : true; - - return Task.FromResult(result); - } - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/PeriodicBatching/BoundedConcurrentQueueTests.cs b/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/PeriodicBatching/BoundedConcurrentQueueTests.cs deleted file mode 100644 index fc07d37fc..000000000 --- a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/PeriodicBatching/BoundedConcurrentQueueTests.cs +++ /dev/null @@ -1,60 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// -// Based on https://github.com/serilog/serilog-sinks-periodicbatching/blob/66a74768196758200bff67077167cde3a7e346d5/test/Serilog.Sinks.PeriodicBatching.Tests/BoundedConcurrentQueueTests.cs - -using System; -using Datadog.Trace.Util; -using FluentAssertions; -using Xunit; - -namespace Datadog.Trace.Tests.Logging.DirectSubmission.Sink.PeriodicBatching -{ - public class BoundedConcurrentQueueTests - { - [Fact] - public void WhenBoundedShouldNotExceedLimit() - { - const int limit = 100; - var queue = new BoundedConcurrentQueue(limit); - - for (var i = 0; i < limit * 2; i++) - { - queue.TryEnqueue(i); - } - - queue.InnerQueue.Count.Should().Be(limit); - } - - [Theory] - [InlineData(-42)] - [InlineData(0)] - public void WhenInvalidLimitWillThrow(int limit) - { - Assert.Throws(() => new BoundedConcurrentQueue(limit)); - } - - [Fact] - public void CheckCount() - { - const int limit = 5; - var queue = new BoundedConcurrentQueue(limit); - - for (var i = 0; i < limit; i++) - { - queue.TryEnqueue(i); - queue.Count.Should().Be(i + 1); - } - } - - [Fact] - public void CheckIsEmpty() - { - var queue = new BoundedConcurrentQueue(5); - queue.IsEmpty.Should().BeTrue(); - queue.TryEnqueue(5); - queue.IsEmpty.Should().BeFalse(); - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/PeriodicBatching/CircuitBreakerTests.cs b/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/PeriodicBatching/CircuitBreakerTests.cs deleted file mode 100644 index 16a6c5c47..000000000 --- a/tracer/test/Datadog.Trace.Tests/Logging/DirectSubmission/Sink/PeriodicBatching/CircuitBreakerTests.cs +++ /dev/null @@ -1,128 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Collections.Generic; -using System.Linq; -using Datadog.Trace.Logging.DirectSubmission.Sink.PeriodicBatching; -using FluentAssertions; -using Xunit; - -namespace Datadog.Trace.Tests.Logging.DirectSubmission.Sink.PeriodicBatching -{ - public class CircuitBreakerTests - { - private const int FailuresUntilBroken = 5; - private readonly CircuitBreaker _circuitBreaker; - - public CircuitBreakerTests() - { - _circuitBreaker = new CircuitBreaker(FailuresUntilBroken); - } - - public static IEnumerable GetAllStatuses() - => Enum.GetValues(typeof(CircuitStatus)) - .Cast() - .Select(x => new object[] { x }); - - [Fact] - public void SuccessAfterHalfBreakClosesCircuit() - { - TryEnterState(CircuitStatus.HalfBroken); - for (var i = 0; i < FailuresUntilBroken - 1; i++) - { - _circuitBreaker.MarkSuccess().Should().Be(CircuitStatus.Closed); - } - } - - [Fact] - public void FailureAfterHalfBreakBreaksCircuit() - { - TryEnterState(CircuitStatus.HalfBroken); - _circuitBreaker.MarkFailure().Should().Be(CircuitStatus.Broken); - } - - [Fact] - public void PermanentBreakIsNeverUndone() - { - TryEnterState(CircuitStatus.PermanentlyBroken); - for (var i = 0; i < 100 - 1; i++) - { - _circuitBreaker.MarkSuccess().Should().Be(CircuitStatus.PermanentlyBroken); - } - } - - [Fact] - public void SuccessAfterBrokenMovesToHalfBreak() - { - TryEnterState(CircuitStatus.Broken); - _circuitBreaker.MarkSuccess().Should().Be(CircuitStatus.HalfBroken); - } - - [Theory] - [MemberData(nameof(GetAllStatuses))] - internal void SkipDoesntChangeStatus_ExceptForBroken(CircuitStatus status) - { - TryEnterState(status); - - if (status == CircuitStatus.Broken) - { - _circuitBreaker.MarkSkipped().Should().Be(CircuitStatus.HalfBroken); - } - else - { - _circuitBreaker.MarkSkipped().Should().Be(status); - } - } - - [Theory] - [MemberData(nameof(GetAllStatuses))] - internal void CanEnterExpectedState(CircuitStatus status) - { - TryEnterState(status); - } - - private void TryEnterState(CircuitStatus required) - { - CircuitStatus actual = default; - switch (required) - { - case CircuitStatus.Closed: - for (var i = 0; i < 100; i++) - { - actual = _circuitBreaker.MarkSuccess(); - } - - break; - - case CircuitStatus.Broken: - actual = _circuitBreaker.MarkSuccess(); - for (var i = 0; i < FailuresUntilBroken; i++) - { - actual = _circuitBreaker.MarkFailure(); - } - - break; - - case CircuitStatus.PermanentlyBroken: - for (var i = 0; i < FailuresUntilBroken; i++) - { - actual = _circuitBreaker.MarkFailure(); - } - - break; - - case CircuitStatus.HalfBroken: - TryEnterState(CircuitStatus.Broken); - actual = _circuitBreaker.MarkSuccess(); - break; - default: - throw new InvalidOperationException("Unknown status: " + required); - } - - actual.Should().Be(required); - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/MockLogsIntakeTests.cs b/tracer/test/Datadog.Trace.Tests/MockLogsIntakeTests.cs deleted file mode 100644 index b0069a2f2..000000000 --- a/tracer/test/Datadog.Trace.Tests/MockLogsIntakeTests.cs +++ /dev/null @@ -1,93 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using Datadog.Trace.Logging.DirectSubmission; -using Datadog.Trace.Logging.DirectSubmission.Formatting; -using Datadog.Trace.TestHelpers; -using Datadog.Trace.Tests.Logging.DirectSubmission; -using Datadog.Trace.Tests.Logging.DirectSubmission.Sink; -using Datadog.Trace.Vendors.Newtonsoft.Json; -using FluentAssertions; -using Xunit; - -namespace Datadog.Trace.Tests -{ - public class MockLogsIntakeTests - { - [Fact] - public void CanDeserializeJson() - { - var serialized = "[{\"@t\":\"2021-09-28T14:47:02.6486114Z\",\"@m\":\"[ExcludeMessage]Building pipeline\",\"@i\":\"c5676978\",\"ddsource\":\"csharp\",\"service\":\"LogsInjection.ILogger\",\"host\":\"integration_ilogger_tests\",\"dd.env\":\"integration_tests\",\"dd.version\":\"1.0.0\",\"trace_id\":\"8172771144023044714\",\"span_id\":\"870590545642546651\"}]"; - using var ms = new MemoryStream(Encoding.UTF8.GetBytes(serialized)); - - var logs = MockLogsIntake.Log.DeserializeFromStream(ms); - - logs.Should().NotBeNull(); - var log = logs.Should().ContainSingle().Subject; - log.Message.Should().Be("[ExcludeMessage]Building pipeline"); - log.EventId.Should().Be("c5676978"); - log.Source.Should().Be("csharp"); - log.Service.Should().Be("LogsInjection.ILogger"); - log.Host.Should().Be("integration_ilogger_tests"); - log.Env.Should().Be("integration_tests"); - log.Version.Should().Be("1.0.0"); - log.TraceId.Should().Be("8172771144023044714"); - log.SpanId.Should().Be("870590545642546651"); - } - - [Fact] - public void CanDeserializeFormattedLogs() - { - var formatter = LogSettingsHelper.GetFormatter(); - var log1 = GetLog(formatter, "This is a {Value}", DirectSubmissionLogLevel.Warning, new Dictionary { { "Value", "SomeValue" } }); - var log2 = GetLog(formatter, "This is another template with some other value", DirectSubmissionLogLevel.Information, new Dictionary { { "Value", "SomeOtherValue" } }); - - var serialized = $"[{log1},{log2}]"; - using var ms = new MemoryStream(Encoding.UTF8.GetBytes(serialized)); - - var logs = MockLogsIntake.Log.DeserializeFromStream(ms); - - logs.Should().NotBeNull(); - logs.Should().HaveCount(2); - } - - private static string GetLog( - LogFormatter formatter, - string message, - DirectSubmissionLogLevel level, - Dictionary properties) - { - var sb = new StringBuilder(); - - formatter.FormatLog( - sb, - sb, // not used here - DateTime.UtcNow, - message, - null, - level.GetName(), - exception: null, - RenderPropertiesDelegate); - return sb.ToString(); - - LogPropertyRenderingDetails RenderPropertiesDelegate(JsonTextWriter writer, in StringBuilder stringBuilder) - { - foreach (var pair in properties) - { - writer.WritePropertyName(pair.Key); - writer.WriteValue(pair.Value); - } - - return new LogPropertyRenderingDetails(false, false, false, false, false, false, message); - } - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Telemetry/CallTargetInvokerTelemetryTests.cs b/tracer/test/Datadog.Trace.Tests/Telemetry/CallTargetInvokerTelemetryTests.cs deleted file mode 100644 index 841e41eb1..000000000 --- a/tracer/test/Datadog.Trace.Tests/Telemetry/CallTargetInvokerTelemetryTests.cs +++ /dev/null @@ -1,141 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Threading.Tasks; -using Datadog.Trace.Agent; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Http.HttpClient.HttpClientHandler; -using Datadog.Trace.ClrProfiler.CallTarget; -using Datadog.Trace.Configuration; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.PlatformHelpers; -using Datadog.Trace.Sampling; -using Datadog.Trace.Telemetry; -using Datadog.Trace.TestHelpers; -using FluentAssertions; -using Moq; -using Xunit; - -namespace Datadog.Trace.Tests.Telemetry -{ - [Collection(nameof(TracerInstanceTestCollection))] - [TracerRestorer] - public class CallTargetInvokerTelemetryTests - { - // This test tests a lot at once because everything is heavily statically cached, - // which makes tests brittle to order and concurrency etc - [Fact] - public void RecordsRelevantTelemetry() - { - var settings = new TracerSettings() { ServiceName = "DefaultService" }; - var telemetry = new TestTelemetryController(); - var tracer = new Tracer( - settings, - new Mock().Object, - new Mock().Object, - scopeManager: null, - statsd: null, - telemetry: telemetry); - - Tracer.UnsafeSetTracerInstance(tracer); - telemetry.RunningInvocations.Should().BeEmpty(); - - try - { - CallTargetInvoker.BeginMethod(new HttpClientHandler()); - } - catch (Exception) - { - // this will throw but we don't actually care - } - - telemetry.RunningInvocations.Should().ContainSingle(); - - var runInvocation = telemetry.RunningInvocations[0]; - runInvocation.Should().Be(IntegrationId.HttpMessageHandler); - - try - { - CallTargetInvoker.BeginMethod(new HttpClientHandler()); - } - catch (Exception) - { - // this will throw but we don't actually care - } - - telemetry.RunningInvocations.Should().HaveCount(2); - telemetry.RunningInvocations.Should().AllBeEquivalentTo(runInvocation); - - // Now track errors - - var untrackedException = new Exception("I'm not tracked"); - CallTargetInvoker.LogException(untrackedException); - telemetry.ErrorInvocations.Should().BeEmpty(); - - // Either of these should work, but we can't test both, as we only record the first exception for now - Exception exception = null; - try - { - DuckTypeException.Throw("A DuckTypeException occured"); - } - catch (Exception ex) - { - exception = ex; - } - - // var exception = new CallTargetInvokerException(new Exception("A CallTargetInvokerException occurred")); - - CallTargetInvoker.LogException(exception); - telemetry.ErrorInvocations.Should().ContainSingle(); - - var invocation = telemetry.ErrorInvocations[0]; - invocation.Info.Should().Be(IntegrationId.HttpMessageHandler); - invocation.Error.Should().Be(nameof(DuckTypeException)); - } - - internal class TestTelemetryController : ITelemetryController - { - public List RunningInvocations { get; } = new(); - - public List<(IntegrationId Info, string Error)> ErrorInvocations { get; } = new(); - - public void IntegrationRunning(IntegrationId info) - { - RunningInvocations.Add(info); - } - - public void IntegrationGeneratedSpan(IntegrationId info) - { - } - - public void IntegrationDisabledDueToError(IntegrationId info, string error) - { - ErrorInvocations.Add((info, error)); - } - - public void RecordTracerSettings(ImmutableTracerSettings settings, string defaultServiceName, AzureAppServices appServicesMetadata) - { - } - - public Task DisposeAsync(bool sendAppClosingTelemetry) - { - return Task.CompletedTask; - } - - public Task DisposeAsync() - { - return Task.CompletedTask; - } - - public void Start() - { - } - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Telemetry/Collectors/ConfigurationTelemetryCollectorTests.cs b/tracer/test/Datadog.Trace.Tests/Telemetry/Collectors/ConfigurationTelemetryCollectorTests.cs deleted file mode 100644 index 38c947f70..000000000 --- a/tracer/test/Datadog.Trace.Tests/Telemetry/Collectors/ConfigurationTelemetryCollectorTests.cs +++ /dev/null @@ -1,203 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.Linq; -#if NETFRAMEWORK -using System.Security; -using System.Security.Permissions; -#endif -using Datadog.Trace.Configuration; -using Datadog.Trace.PlatformHelpers; -using Datadog.Trace.Telemetry; -using FluentAssertions; -using FluentAssertions.Execution; -using Xunit; - -namespace Datadog.Trace.Tests.Telemetry -{ - public class ConfigurationTelemetryCollectorTests - { - private const string ServiceName = "serializer-test-app"; - private static readonly AzureAppServices EmptyAasSettings = new(new Dictionary()); - - [Fact] - public void HasChangesAfterEachTracerSettingsAdded() - { - var settings = new ImmutableTracerSettings(new TracerSettings()); - - var collector = new ConfigurationTelemetryCollector(); - - collector.RecordTracerSettings(settings, ServiceName, EmptyAasSettings); - - collector.HasChanges().Should().BeTrue(); - var data = collector.GetConfigurationData() - .ToDictionary(x => x.Name, x => x.Value); - data[ConfigTelemetryData.TracerInstanceCount] = 1; - collector.HasChanges().Should().BeFalse(); - - collector.RecordTracerSettings(settings, ServiceName, EmptyAasSettings); - collector.HasChanges().Should().BeTrue(); - - data = collector.GetConfigurationData().ToDictionary(x => x.Name, x => x.Value); - data[ConfigTelemetryData.TracerInstanceCount] = 2; - collector.HasChanges().Should().BeFalse(); - } - - [Fact] - public void ApplicationDataShouldIncludeExpectedValues() - { - const string env = "serializer-tests"; - const string serviceVersion = "1.2.3"; - var settings = new TracerSettings() { ServiceName = ServiceName, Environment = env, ServiceVersion = serviceVersion }; - - var collector = new ConfigurationTelemetryCollector(); - - collector.RecordTracerSettings(new ImmutableTracerSettings(settings), ServiceName, EmptyAasSettings); - - var data = collector.GetApplicationData(); - - data.ServiceName.Should().Be(ServiceName); - data.Env.Should().Be(env); - data.TracerVersion.Should().Be(TracerConstants.AssemblyVersion); - data.LanguageName.Should().Be("dotnet"); - data.ServiceVersion.Should().Be(serviceVersion); - data.LanguageVersion.Should().Be(FrameworkDescription.Instance.ProductVersion); - data.RuntimeName.Should().NotBeNullOrEmpty().And.Be(FrameworkDescription.Instance.Name); - data.RuntimeVersion.Should().BeNull(); - } - - [Fact] - public void ConfigurationDataShouldIncludeAzureValuesWhenInAzureAndSafeToTrace() - { - const string env = "serializer-tests"; - const string serviceVersion = "1.2.3"; - var settings = new TracerSettings() { ServiceName = ServiceName, Environment = env, ServiceVersion = serviceVersion }; - var aas = new AzureAppServices(new Dictionary - { - { ConfigurationKeys.SignalFxAccessToken, "SomeValue" }, - { AzureAppServices.AzureAppServicesContextKey, "1" }, - { AzureAppServices.SiteExtensionVersionKey, "1.5.0" }, - { AzureAppServices.FunctionsExtensionVersionKey, "~3" }, - }); - - var collector = new ConfigurationTelemetryCollector(); - - collector.RecordTracerSettings(new ImmutableTracerSettings(settings), ServiceName, aas); - - var data = collector.GetConfigurationData() - .ToDictionary(x => x.Name, x => x.Value); - - using var scope = new AssertionScope(); - data[ConfigTelemetryData.AasConfigurationError].Should().BeOfType().Subject.Should().BeFalse(); - data[ConfigTelemetryData.CloudHosting].Should().Be("Azure"); - data[ConfigTelemetryData.AasAppType].Should().Be("function"); - data[ConfigTelemetryData.AasFunctionsRuntimeVersion].Should().Be("~3"); - data[ConfigTelemetryData.AasSiteExtensionVersion].Should().Be("1.5.0"); - } - - [Fact] - public void ConfigurationDataShouldNotIncludeAzureValuesWhenInAzureAndNotSafeToTrace() - { - const string env = "serializer-tests"; - const string serviceVersion = "1.2.3"; - var settings = new TracerSettings() { ServiceName = ServiceName, Environment = env, ServiceVersion = serviceVersion }; - var aas = new AzureAppServices(new Dictionary - { - // Without a SIGNALFX_API_KEY, AAS does not consider it safe to trace - // { ConfigurationKeys.SignalFxAccessToken, "SomeValue" }, - { AzureAppServices.AzureAppServicesContextKey, "1" }, - { AzureAppServices.SiteExtensionVersionKey, "1.5.0" }, - { AzureAppServices.FunctionsExtensionVersionKey, "~3" }, - }); - - var collector = new ConfigurationTelemetryCollector(); - - collector.RecordTracerSettings(new ImmutableTracerSettings(settings), ServiceName, aas); - - var data = collector.GetConfigurationData() - .ToDictionary(x => x.Name, x => x.Value); - - using var scope = new AssertionScope(); - data[ConfigTelemetryData.AasConfigurationError].Should().BeOfType().Subject.Should().BeTrue(); - data[ConfigTelemetryData.CloudHosting].Should().Be("Azure"); - // TODO: Don't we want to collect these anyway? If so, need to update AzureAppServices behaviour - data[ConfigTelemetryData.AasAppType].Should().BeNull(); - data[ConfigTelemetryData.AasFunctionsRuntimeVersion].Should().BeNull(); - data[ConfigTelemetryData.AasSiteExtensionVersion].Should().BeNull(); - } - - [Fact] - public void ConfigurationDataShouldNotIncludeAzureValuesWhenNotInAzure() - { - const string env = "serializer-tests"; - const string serviceVersion = "1.2.3"; - var settings = new TracerSettings() { ServiceName = ServiceName, Environment = env, ServiceVersion = serviceVersion }; - - var collector = new ConfigurationTelemetryCollector(); - - collector.RecordTracerSettings(new ImmutableTracerSettings(settings), ServiceName, EmptyAasSettings); - - var data = collector.GetConfigurationData() - .ToDictionary(x => x.Name, x => x.Value); - - using var scope = new AssertionScope(); - data.Should().NotContainKey(ConfigTelemetryData.CloudHosting); - data.Should().NotContainKey(ConfigTelemetryData.AasAppType); - data.Should().NotContainKey(ConfigTelemetryData.AasFunctionsRuntimeVersion); - data.Should().NotContainKey(ConfigTelemetryData.AasSiteExtensionVersion); - } - -#if NETFRAMEWORK - [Theory(Skip = "Needs investigation")] - [InlineData(false)] - [InlineData(true)] - public void ConfigurationDataShouldIncludeExpectedFullTrustValues(bool isFullTrust) - { - Dictionary data; - if (isFullTrust) - { - var carrier = new AppDomainCarrierClass(); - data = carrier.BuildFullTrustConfigurationData(); - } - else - { - PermissionSet permSet = new PermissionSet(PermissionState.None); - permSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution)); - permSet.AddPermission(new EnvironmentPermission(PermissionState.Unrestricted)); // The module initializer in the test DLL sets an environment variable to disable telemetry - var remote = AppDomain.CreateDomain("ConfigurationDataShouldIncludeExpectedFullTrustValues", null, AppDomain.CurrentDomain.SetupInformation, permSet); - - var carrierType = typeof(AppDomainCarrierClass); - var carrier = (AppDomainCarrierClass)remote.CreateInstanceAndUnwrap(carrierType.Assembly.FullName, carrierType.FullName); - data = carrier.BuildFullTrustConfigurationData(); - } - - data[ConfigTelemetryData.FullTrustAppDomain].Should().Be(isFullTrust); - } - - public class AppDomainCarrierClass : MarshalByRefObject - { - public Dictionary BuildFullTrustConfigurationData() - { - const string env = "serializer-tests"; - const string serviceVersion = "1.2.3"; - var settings = new TracerSettings() { ServiceName = ServiceName, Environment = env, ServiceVersion = serviceVersion }; - - var collector = new ConfigurationTelemetryCollector(); - - collector.RecordTracerSettings(new ImmutableTracerSettings(settings), ServiceName, EmptyAasSettings); - - var data = collector.GetConfigurationData() - .ToDictionary(x => x.Name, x => x.Value); - return data; - } - } -#endif - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Telemetry/Collectors/DependencyTelemetryCollectorTests.cs b/tracer/test/Datadog.Trace.Tests/Telemetry/Collectors/DependencyTelemetryCollectorTests.cs deleted file mode 100644 index 29989c9de..000000000 --- a/tracer/test/Datadog.Trace.Tests/Telemetry/Collectors/DependencyTelemetryCollectorTests.cs +++ /dev/null @@ -1,143 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.IO; -using System.Linq; -using System.Reflection; -using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging.Serilog.DirectSubmission; -using Datadog.Trace.DuckTyping; -using Datadog.Trace.Telemetry; -using Datadog.Trace.Vendors.Serilog.Events; -using Datadog.Trace.Vendors.Serilog.Parsing; -using FluentAssertions; -using Xunit; - -namespace Datadog.Trace.Tests.Telemetry -{ - public class DependencyTelemetryCollectorTests - { - [Fact] - public void HasChangesAfterAssemblyLoaded() - { - var collector = new DependencyTelemetryCollector(); - - var data = collector.GetData(); - data.Should().BeNull(); - collector.HasChanges().Should().BeFalse(); - - var assembly = typeof(DependencyTelemetryCollectorTests).Assembly; - collector.AssemblyLoaded(assembly); - - collector.HasChanges().Should().BeTrue(); - - data = collector.GetData(); - data.Should() - .HaveCount(1) - .And.ContainSingle(x => x.Name == "Datadog.Trace.Tests"); - collector.HasChanges().Should().BeFalse(); - } - - [Fact] - public void DoesNotHaveChangesWhenSameAssemblyAddedTwice() - { - var assembly = typeof(DependencyTelemetryCollectorTests).Assembly; - var collector = new DependencyTelemetryCollector(); - collector.AssemblyLoaded(assembly); - - collector.GetData(); - collector.HasChanges().Should().BeFalse(); - - collector.AssemblyLoaded(assembly); - collector.HasChanges().Should().BeFalse(); - } - - [Theory] - [InlineData("App_global.asax.zt8edv4m")] - [InlineData("App_Web_login.cshtml.6331810a.tvsbhzc3")] - [InlineData("App_GlobalResources.9ccedwue")] - [InlineData("App_Code.hhzpytyv")] - [InlineData("App_Theme_Standard.6wkna0wf")] - [InlineData("App_WebReferences.dvkaf7ph")] - [InlineData("0018eae6-bd49-41a4-9bd2-6be3a6544a15")] - [InlineData("005ec706-91d7-4237-9466-bac51a64d90f")] - [InlineData("00821386-7d9a-499b-8e7f-53dbbefcaf3d")] - [InlineData("OK_IM_NO-GUID-BUUT-NOT_-THAT_FAR_OFF")] - public void DoesNotHaveChangesWhenAssemblyNameIsIgnoredAssembly(string assemblyName) - { - var ignoredName = CreateAssemblyName(new Version(1, 0), name: assemblyName); - - var collector = new DependencyTelemetryCollector(); - collector.AssemblyLoaded(ignoredName); - - collector.HasChanges().Should().BeFalse(); - } - - [Fact] - public void DoesNotHaveChangesWhenUsingDuckTypeAssembly() - { - // create a random proxy (this needs to succeed, but can be anything) - var original = new LogEvent( - DateTimeOffset.UtcNow, - LogEventLevel.Debug, - exception: null, - new MessageTemplate("Some text", Enumerable.Empty()), - Enumerable.Empty()); - var proxy = original.DuckCast(); - - var assembly = proxy.GetType().Assembly; - - var collector = new DependencyTelemetryCollector(); - collector.AssemblyLoaded(assembly); - - collector.HasChanges().Should().BeFalse(); - } - - [Fact] - public void DoesNotHaveChangesWhenAssemblyNameIsTempPath() - { - for (var i = 0; i < 1_000; i++) - { - var name = Path.GetRandomFileName(); - var ignoredName = CreateAssemblyName(new Version(1, 0), name: name); - - var collector = new DependencyTelemetryCollector(); - collector.AssemblyLoaded(ignoredName); - - collector.HasChanges().Should().BeFalse($"{name} is a temp file name"); - } - } - - [Fact] - public void HasChangesWhenAddingSameAssemblyWithDifferentVersion() - { - var assemblyV1 = CreateAssemblyName(new Version(1, 0)); - var assemblyV2 = CreateAssemblyName(new Version(2, 0)); - var collector = new DependencyTelemetryCollector(); - collector.AssemblyLoaded(assemblyV1); - - collector.GetData(); - collector.HasChanges().Should().BeFalse(); - - collector.AssemblyLoaded(assemblyV2); - collector.HasChanges().Should().BeTrue(); - var data = collector.GetData(); - data.Should().NotBeNull(); - data.Should() - .NotBeNullOrEmpty() - .And.HaveCount(2) - .And.OnlyHaveUniqueItems(); - } - - private static AssemblyName CreateAssemblyName(Version version = null, string name = null) - { - return new AssemblyName() - { - Name = name ?? "Datadog.Trace.Test.DynamicAssembly", - Version = version, - }; - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Telemetry/Collectors/IntegrationTelemetryCollectorTests.cs b/tracer/test/Datadog.Trace.Tests/Telemetry/Collectors/IntegrationTelemetryCollectorTests.cs deleted file mode 100644 index f6090583b..000000000 --- a/tracer/test/Datadog.Trace.Tests/Telemetry/Collectors/IntegrationTelemetryCollectorTests.cs +++ /dev/null @@ -1,184 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System.Collections.Generic; -using System.Linq; -using Datadog.Trace.Configuration; -using Datadog.Trace.PlatformHelpers; -using Datadog.Trace.Telemetry; -using FluentAssertions; -using Xunit; -using Xunit.Abstractions; - -namespace Datadog.Trace.Tests.Telemetry -{ - public class IntegrationTelemetryCollectorTests - { - private const IntegrationId IntegrationId = Trace.Configuration.IntegrationId.Kafka; - private static readonly string IntegrationName = ValuesRegistry.GetName(IntegrationId); - - [Fact] - public void HasChangesWhenNewIntegrationRunning() - { - var collector = new IntegrationTelemetryCollector(); - collector.RecordTracerSettings(new ImmutableTracerSettings(new TracerSettings())); - - collector.GetData(); - collector.HasChanges().Should().BeFalse(); - - collector.IntegrationRunning(IntegrationId); - collector.HasChanges().Should().BeTrue(); - } - - [Fact] - public void DoesNotHaveChangesWhenSameIntegrationRunning() - { - var collector = new IntegrationTelemetryCollector(); - collector.RecordTracerSettings(new ImmutableTracerSettings(new TracerSettings())); - - collector.GetData(); - collector.HasChanges().Should().BeFalse(); - - collector.IntegrationRunning(IntegrationId); - collector.HasChanges().Should().BeTrue(); - collector.GetData(); - - collector.IntegrationRunning(IntegrationId); - collector.HasChanges().Should().BeFalse(); - } - - [Fact] - public void HasChangesWhenNewIntegrationGeneratedSpan() - { - var collector = new IntegrationTelemetryCollector(); - collector.RecordTracerSettings(new ImmutableTracerSettings(new TracerSettings())); - - collector.GetData(); - collector.HasChanges().Should().BeFalse(); - - collector.IntegrationGeneratedSpan(IntegrationId); - collector.HasChanges().Should().BeTrue(); - } - - [Fact] - public void DoesNotHaveChangesWhenSameIntegrationGeneratedSpan() - { - var collector = new IntegrationTelemetryCollector(); - collector.RecordTracerSettings(new ImmutableTracerSettings(new TracerSettings())); - - collector.GetData(); - collector.HasChanges().Should().BeFalse(); - - collector.IntegrationGeneratedSpan(IntegrationId); - collector.HasChanges().Should().BeTrue(); - collector.GetData(); - - collector.IntegrationGeneratedSpan(IntegrationId); - collector.HasChanges().Should().BeFalse(); - } - - [Fact] - public void HasChangesWhenNewIntegrationDisabled() - { - var collector = new IntegrationTelemetryCollector(); - collector.RecordTracerSettings(new ImmutableTracerSettings(new TracerSettings())); - - collector.GetData(); - collector.HasChanges().Should().BeFalse(); - - collector.IntegrationDisabledDueToError(IntegrationId, "Testing!"); - collector.HasChanges().Should().BeTrue(); - } - - [Fact] - public void DoesNotHaveChangesWhenSameIntegrationDisabled() - { - var collector = new IntegrationTelemetryCollector(); - collector.RecordTracerSettings(new ImmutableTracerSettings(new TracerSettings())); - - collector.GetData(); - collector.HasChanges().Should().BeFalse(); - - collector.IntegrationDisabledDueToError(IntegrationId, "Testing"); - collector.HasChanges().Should().BeTrue(); - collector.GetData(); - - collector.IntegrationDisabledDueToError(IntegrationId, "Another error"); - collector.HasChanges().Should().BeFalse(); - } - - [Fact] - public void WhenIntegrationRunsSuccessfullyHasExpectedValues() - { - var collector = new IntegrationTelemetryCollector(); - collector.RecordTracerSettings(new ImmutableTracerSettings(new TracerSettings())); - - collector.IntegrationRunning(IntegrationId); - collector.IntegrationGeneratedSpan(IntegrationId); - - var data = collector.GetData(); - var integration = data.FirstOrDefault(x => x.Name == IntegrationName); - integration.Should().NotBeNull(); - integration.AutoEnabled.Should().BeTrue(); - integration.Enabled.Should().BeTrue(); - integration.Error.Should().BeNull(); - } - - [Fact] - public void WhenIntegrationRunsButDoesNotGenerateSpanHasExpectedValues() - { - var collector = new IntegrationTelemetryCollector(); - collector.RecordTracerSettings(new ImmutableTracerSettings(new TracerSettings())); - - collector.IntegrationRunning(IntegrationId); - - var data = collector.GetData(); - var integration = data.FirstOrDefault(x => x.Name == IntegrationName); - integration.Should().NotBeNull(); - integration.AutoEnabled.Should().BeTrue(); - integration.Enabled.Should().BeFalse(); - integration.Error.Should().BeNull(); - } - - [Fact] - public void WhenIntegrationErrorsHasExpectedValues() - { - const string error = "Some error"; - var collector = new IntegrationTelemetryCollector(); - collector.RecordTracerSettings(new ImmutableTracerSettings(new TracerSettings())); - - collector.IntegrationRunning(IntegrationId); - collector.IntegrationDisabledDueToError(IntegrationId, error); - - var data = collector.GetData(); - var integration = data.FirstOrDefault(x => x.Name == IntegrationName); - integration.Should().NotBeNull(); - integration.AutoEnabled.Should().BeTrue(); - integration.Enabled.Should().BeFalse(); - integration.Error.Should().Be(error); - } - - [Fact] - public void WhenIntegrationRunsThenErrorsHasExpectedValues() - { - const string error = "Some error"; - var collector = new IntegrationTelemetryCollector(); - collector.RecordTracerSettings(new ImmutableTracerSettings(new TracerSettings())); - - collector.IntegrationRunning(IntegrationId); - collector.IntegrationGeneratedSpan(IntegrationId); - collector.IntegrationDisabledDueToError(IntegrationId, error); - - var data = collector.GetData(); - var integration = data.FirstOrDefault(x => x.Name == IntegrationName); - integration.Should().NotBeNull(); - integration.AutoEnabled.Should().BeTrue(); - integration.Enabled.Should().BeTrue(); - integration.Error.Should().Be(error); - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Telemetry/TelemetryCircuitBreakerTests.cs b/tracer/test/Datadog.Trace.Tests/Telemetry/TelemetryCircuitBreakerTests.cs deleted file mode 100644 index 3f133f449..000000000 --- a/tracer/test/Datadog.Trace.Tests/Telemetry/TelemetryCircuitBreakerTests.cs +++ /dev/null @@ -1,122 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using Datadog.Trace.Telemetry; -using FluentAssertions; -using Xunit; - -namespace Datadog.Trace.Tests.Telemetry -{ - public class TelemetryCircuitBreakerTests - { - private readonly TelemetryCircuitBreaker _circuitBreaker = new(); - - [Fact] - public void WhenHaveSuccess_ReturnsSuccess() - { - var result = TelemetryPushResult.Success; - var config = Array.Empty(); - var deps = Array.Empty(); - var integrations = Array.Empty(); - - for (var i = 0; i < 10; i++) - { - var telemetryPushResult = _circuitBreaker.Evaluate(result, config, deps, integrations); - telemetryPushResult.Should().Be(TelemetryPushResult.Success); - _circuitBreaker.PreviousConfiguration.Should().BeNull(); - _circuitBreaker.PreviousDependencies.Should().BeNull(); - _circuitBreaker.PreviousIntegrations.Should().BeNull(); - } - } - - [Theory] - [InlineData((int)TelemetryPushResult.TransientFailure)] - [InlineData((int)TelemetryPushResult.FatalError)] - public void OnInitialError_TreatsAsTransientAndSavesDataForLater(int errorType) - { - var config = Array.Empty(); - var deps = Array.Empty(); - var integrations = Array.Empty(); - - var telemetryPushResult = _circuitBreaker.Evaluate((TelemetryPushResult)errorType, config, deps, integrations); - - telemetryPushResult.Should().Be(TelemetryPushResult.TransientFailure); - _circuitBreaker.PreviousConfiguration.Should().BeSameAs(config); - _circuitBreaker.PreviousDependencies.Should().BeSameAs(deps); - _circuitBreaker.PreviousIntegrations.Should().BeSameAs(integrations); - } - - [Fact] - public void OnMultipleInitialFatalError_ReturnsFatal() - { - var config = Array.Empty(); - var deps = Array.Empty(); - var integrations = Array.Empty(); - - _circuitBreaker.Evaluate(TelemetryPushResult.FatalError, config, deps, integrations); - var telemetryPushResult = _circuitBreaker.Evaluate(TelemetryPushResult.FatalError, config, deps, integrations); - - telemetryPushResult.Should().Be(TelemetryPushResult.FatalError); - _circuitBreaker.PreviousConfiguration.Should().BeNull(); - _circuitBreaker.PreviousDependencies.Should().BeNull(); - _circuitBreaker.PreviousIntegrations.Should().BeNull(); - } - - [Fact] - public void OnMultipleFatalErrorAfterSuccess_ReturnsTransient() - { - var config = Array.Empty(); - var deps = Array.Empty(); - var integrations = Array.Empty(); - - _circuitBreaker.Evaluate(TelemetryPushResult.Success, config, deps, integrations); - var firstResult = _circuitBreaker.Evaluate(TelemetryPushResult.FatalError, config, deps, integrations); - var secondResult = _circuitBreaker.Evaluate(TelemetryPushResult.FatalError, config, deps, integrations); - - firstResult.Should().Be(TelemetryPushResult.TransientFailure); - secondResult.Should().Be(TelemetryPushResult.TransientFailure); - } - - [Theory] - [InlineData((int)TelemetryPushResult.FatalError)] - [InlineData((int)TelemetryPushResult.TransientFailure)] - public void OnMultipleTransientErrorsAfterSuccess_ReturnsFatal(int errorType) - { - var config = Array.Empty(); - var deps = Array.Empty(); - var integrations = Array.Empty(); - - _circuitBreaker.Evaluate(TelemetryPushResult.Success, config, deps, integrations); - for (var i = 0; i < TelemetryCircuitBreaker.MaxTransientErrors - 1; i++) - { - var result = _circuitBreaker.Evaluate((TelemetryPushResult)errorType, config, deps, integrations); - result.Should().Be(TelemetryPushResult.TransientFailure); - } - - var finalResult = _circuitBreaker.Evaluate(TelemetryPushResult.FatalError, config, deps, integrations); - - finalResult.Should().Be(TelemetryPushResult.FatalError); - _circuitBreaker.PreviousConfiguration.Should().BeNull(); - _circuitBreaker.PreviousDependencies.Should().BeNull(); - _circuitBreaker.PreviousIntegrations.Should().BeNull(); - } - - [Fact] - public void OnSuccessAfterTransient_ClearsPreviousConfig() - { - var config = Array.Empty(); - var deps = Array.Empty(); - var integrations = Array.Empty(); - - _circuitBreaker.Evaluate(TelemetryPushResult.TransientFailure, config, deps, integrations); - _circuitBreaker.Evaluate(TelemetryPushResult.Success, config, deps, integrations); - - _circuitBreaker.PreviousConfiguration.Should().BeNull(); - _circuitBreaker.PreviousDependencies.Should().BeNull(); - _circuitBreaker.PreviousIntegrations.Should().BeNull(); - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Telemetry/TelemetryControllerTests.cs b/tracer/test/Datadog.Trace.Tests/Telemetry/TelemetryControllerTests.cs deleted file mode 100644 index 3666497e2..000000000 --- a/tracer/test/Datadog.Trace.Tests/Telemetry/TelemetryControllerTests.cs +++ /dev/null @@ -1,183 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Datadog.Trace.Configuration; -using Datadog.Trace.PlatformHelpers; -using Datadog.Trace.Telemetry; -using FluentAssertions; -using FluentAssertions.Execution; -using Xunit; - -namespace Datadog.Trace.Tests.Telemetry -{ - public class TelemetryControllerTests : IDisposable - { - private static readonly AzureAppServices EmptyAasMetadata = new(new Dictionary()); - private readonly TimeSpan _refreshInterval = TimeSpan.FromMilliseconds(100); - private readonly TimeSpan _timeout = TimeSpan.FromMilliseconds(60_000); // definitely should receive telemetry by now - private readonly TestTelemetryTransport _transport; - private readonly TelemetryController _controller; - - public TelemetryControllerTests() - { - _transport = new TestTelemetryTransport(pushResult: TelemetryPushResult.Success); - _controller = new TelemetryController( - new ConfigurationTelemetryCollector(), - new DependencyTelemetryCollector(), - new IntegrationTelemetryCollector(), - _transport, - _refreshInterval); - } - - public void Dispose() => _controller?.DisposeAsync(); - - [Fact] - public async Task TelemetryControllerShouldSendTelemetry() - { - _controller.RecordTracerSettings(new ImmutableTracerSettings(new TracerSettings()), "DefaultServiceName", EmptyAasMetadata); - _controller.Start(); - - var data = await WaitForRequestStarted(_transport, _timeout); - } - - [Fact] - public async Task TelemetryControllerCanBeDisposedTwice() - { - await _controller.DisposeAsync(); - await _controller.DisposeAsync(); - } - - [Fact] - public async Task TelemetryControllerDisposesOnTwoFatalErrorsFromTelemetry() - { - var transport = new TestTelemetryTransport(pushResult: TelemetryPushResult.FatalError); // fail to push telemetry - var controller = new TelemetryController( - new ConfigurationTelemetryCollector(), - new DependencyTelemetryCollector(), - new IntegrationTelemetryCollector(), - transport, - _refreshInterval); - - controller.RecordTracerSettings(new ImmutableTracerSettings(new TracerSettings()), "DefaultServiceName", EmptyAasMetadata); - controller.Start(); - - (await WaitForFatalError(controller)).Should().BeTrue("controller should be disposed on failed push"); - - var previousDataCount = transport.GetData(); - - previousDataCount - .Should() - .OnlyContain(x => x.RequestType == TelemetryRequestTypes.AppStarted, "Fatal error should mean we try to send app-started twice"); - - controller.IntegrationRunning(IntegrationId.Kafka); - - // Shouldn't receive any more data, - await Task.Delay(3_000); - transport.GetData().Count.Should().Be(previousDataCount.Count, "Should not send more data after disposal"); - } - - [Fact] - public async Task TelemetryControllerAddsAllAssembliesToCollector() - { - var currentAssemblyNames = AppDomain.CurrentDomain - .GetAssemblies() - .Where(x => !x.IsDynamic) - .Select(x => x.GetName()) - .Select(name => new { name.Name, Version = name.Version.ToString() }); - - // creating a new controller so we have the same list of assemblies - var controller = new TelemetryController( - new ConfigurationTelemetryCollector(), - new DependencyTelemetryCollector(), - new IntegrationTelemetryCollector(), - _transport, - _refreshInterval); - - controller.RecordTracerSettings(new ImmutableTracerSettings(new TracerSettings()), "DefaultServiceName", EmptyAasMetadata); - controller.Start(); - - var allData = await WaitForRequestStarted(_transport, _timeout); - var payload = allData - .Where(x => x.RequestType == TelemetryRequestTypes.AppStarted) - .OrderByDescending(x => x.SeqId) - .First() - .Payload as AppStartedPayload; - - payload.Should().NotBeNull(); - - // should contain all the assemblies - using var a = new AssertionScope(); - foreach (var assemblyName in currentAssemblyNames) - { - payload.Dependencies - .Should() - .ContainEquivalentOf(assemblyName); - } - } - - private async Task> WaitForRequestStarted(TestTelemetryTransport transport, TimeSpan timeout) - { - var deadline = DateTimeOffset.UtcNow.Add(timeout); - while (DateTimeOffset.UtcNow < deadline) - { - var data = transport.GetData(); - if (data.Any(x => x.RequestType == TelemetryRequestTypes.AppStarted)) - { - return data; - } - - await Task.Delay(_refreshInterval); - } - - throw new TimeoutException($"Transport did not receive required data before the timeout {timeout.TotalMilliseconds}ms"); - } - - private async Task WaitForFatalError(TelemetryController controller) - { - var deadline = DateTimeOffset.UtcNow.Add(_timeout); - while (DateTimeOffset.UtcNow < deadline) - { - if (controller.FatalError) - { - // was disposed - return true; - } - - await Task.Delay(_refreshInterval); - } - - return false; - } - - internal class TestTelemetryTransport : ITelemetryTransport - { - private readonly ConcurrentStack _data = new(); - private readonly TelemetryPushResult _pushResult; - - public TestTelemetryTransport(TelemetryPushResult pushResult) - { - _pushResult = pushResult; - } - - public List GetData() - { - return _data.ToList(); - } - - public Task PushTelemetry(TelemetryData data) - { - _data.Push(data); - return Task.FromResult(_pushResult); - } - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Telemetry/TelemetryDataBuilderTests.cs b/tracer/test/Datadog.Trace.Tests/Telemetry/TelemetryDataBuilderTests.cs deleted file mode 100644 index 5bbf0b599..000000000 --- a/tracer/test/Datadog.Trace.Tests/Telemetry/TelemetryDataBuilderTests.cs +++ /dev/null @@ -1,149 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Collections.Generic; -using System.Linq; -using Datadog.Trace.Telemetry; -using FluentAssertions; -using FluentAssertions.Execution; -using Xunit; - -namespace Datadog.Trace.Tests.Telemetry -{ - public class TelemetryDataBuilderTests - { - private readonly ApplicationTelemetryData _application; - private readonly HostTelemetryData _host; - - public TelemetryDataBuilderTests() - { - _application = new ApplicationTelemetryData( - serviceName: "Test Service", - env: "integration-ci", - tracerVersion: TracerConstants.AssemblyVersion, - languageName: "dotnet", - languageVersion: FrameworkDescription.Instance.ProductVersion); - _host = new HostTelemetryData(); - } - - [Fact] - public void WhenNoApplicationData_Throws() - { - var builder = new TelemetryDataBuilder(); - - Assert.Throws(() => builder.BuildTelemetryData(null, _host, null, null, null, sendHeartbeat: true)); - Assert.Throws(() => builder.BuildTelemetryData(_application, null, null, null, null, sendHeartbeat: true)); - - Assert.Throws(() => builder.BuildAppClosingTelemetryData(null, _host)); - Assert.Throws(() => builder.BuildAppClosingTelemetryData(_application, null)); - } - - [Fact] - public void WhenHasApplicationAndHostData_GeneratesAppClosingTelemetry() - { - var builder = new TelemetryDataBuilder(); - - var result = builder.BuildAppClosingTelemetryData(_application, _host); - - result.Should().NotBeNull(); - result.Application.Should().Be(_application); - result.SeqId.Should().Be(1); - result.Payload.Should().BeNull(); - } - - [Fact] - public void ShouldGenerateIncrementingIds() - { - var builder = new TelemetryDataBuilder(); - - var config = Array.Empty(); - var data = builder.BuildTelemetryData(_application, _host, config, null, null, sendHeartbeat: true); - data.Should().ContainSingle().Which.SeqId.Should().Be(1); - - data = builder.BuildTelemetryData(_application, _host, config, null, null, sendHeartbeat: true); - data.Should().ContainSingle().Which.SeqId.Should().Be(2); - - var closingData = builder.BuildAppClosingTelemetryData(_application, _host); - closingData.Should().NotBeNull(); - closingData.SeqId.Should().Be(3); - } - - [Theory] - [MemberData(nameof(TestData.Data), MemberType = typeof(TestData))] - public void GeneratesExpectedRequestType( - bool hasConfiguration, - bool hasDependencies, - bool hasIntegrations, - bool sendHeartBeat, - string expectedRequests) - { - var config = hasConfiguration ? Array.Empty() : null; - var dependencies = hasDependencies ? new List() : null; - var integrations = hasIntegrations ? new List() : null; - var expected = string.IsNullOrEmpty(expectedRequests) ? Array.Empty() : expectedRequests.Split(','); - var builder = new TelemetryDataBuilder(); - - var result = builder.BuildTelemetryData(_application, _host, config, dependencies, integrations, sendHeartBeat); - - result.Should().NotBeNull(); - result.Select(x => x.RequestType) - .ToArray() - .Should().BeEquivalentTo(expected); - - using var scope = new AssertionScope(); - - // should have incrementing IDs - result - .Select(x => x.SeqId) - .Should() - .OnlyHaveUniqueItems(); - - foreach (var data in result) - { - data.Application.Should().Be(_application); - data.ApiVersion.Should().NotBeNullOrEmpty(); - data.RuntimeId.Should().Be(ClrProfiler.DistributedTracer.Instance.GetRuntimeId()); - data.TracerTime.Should().BeInRange(0, DateTimeOffset.UtcNow.ToUnixTimeSeconds()); - - if (data.Payload is AppDependenciesLoadedPayload appDeps) - { - appDeps.Dependencies.Should().BeSameAs(dependencies); - } - else if (data.Payload is AppIntegrationsChangedPayload appIntegrations) - { - appIntegrations.Integrations.Should().BeSameAs(integrations); - } - else if (data.Payload is AppStartedPayload appStarted) - { - appStarted.Configuration.Should().BeSameAs(config); - appStarted.Dependencies.Should().BeSameAs(dependencies); - appStarted.Integrations.Should().BeSameAs(integrations); - } - else - { - data.Payload.Should().BeNull(); - } - } - } - - public class TestData - { - public static TheoryData Data => new() - // configuration, dependencies, integrations, sendHeartBeat expected request types - { - { true, true, true, true, TelemetryRequestTypes.AppStarted }, - { true, true, false, true, TelemetryRequestTypes.AppStarted }, - { true, false, true, true, TelemetryRequestTypes.AppStarted }, - { true, false, false, true, TelemetryRequestTypes.AppStarted }, - { false, false, false, true, TelemetryRequestTypes.AppHeartbeat }, - { false, false, false, false, string.Empty }, - { false, true, false, true, TelemetryRequestTypes.AppDependenciesLoaded }, - { false, false, true, true, TelemetryRequestTypes.AppIntegrationsChanged }, - { false, true, true, true, $"{TelemetryRequestTypes.AppIntegrationsChanged},{TelemetryRequestTypes.AppDependenciesLoaded}" }, - }; - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Telemetry/TelemetrySettingsTests.cs b/tracer/test/Datadog.Trace.Tests/Telemetry/TelemetrySettingsTests.cs deleted file mode 100644 index 7e569db99..000000000 --- a/tracer/test/Datadog.Trace.Tests/Telemetry/TelemetrySettingsTests.cs +++ /dev/null @@ -1,243 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -// Modified by Splunk Inc. - -using System.Collections.Specialized; -using Datadog.Trace.Configuration; -using Datadog.Trace.Telemetry; -using FluentAssertions; -using FluentAssertions.Execution; -using Xunit; - -namespace Datadog.Trace.Tests.Telemetry -{ - public class TelemetrySettingsTests - { - private const string DefaultIntakeUrl = "https://instrumentation-telemetry-intake.datadoghq.com/"; - - [Theory] - [InlineData("https://sometest.com", "https://sometest.com/")] - [InlineData("https://sometest.com/some-path", "https://sometest.com/some-path/")] - [InlineData("https://sometest.com/some-path/", "https://sometest.com/some-path/")] - public void WhenValidUrlIsProvided_AndAgentless_AppendsSlashToPath(string url, string expected) - { - var source = new NameValueConfigurationSource(new NameValueCollection - { - { ConfigurationKeys.Telemetry.Enabled, "1" }, - { ConfigurationKeys.Telemetry.Uri, url }, - { ConfigurationKeys.ApiKey, "some_key" }, - }); - - var settings = TelemetrySettings.FromSource(source); - settings.Agentless.Should().NotBeNull(); - settings.Agentless.AgentlessUri.Should().Be(expected); - settings.ConfigurationError.Should().BeNullOrEmpty(); - } - - [Fact] - public void WhenNoUrlOrApiKeyIsProvided_AgentlessIsNotEnabled() - { - var source = new NameValueConfigurationSource(new NameValueCollection - { - { ConfigurationKeys.Telemetry.Enabled, "1" } - }); - - var settings = TelemetrySettings.FromSource(source); - settings.Agentless.Should().BeNull(); - settings.ConfigurationError.Should().BeNullOrEmpty(); - } - - [Fact] - public void WhenOnlyApiKeyIsProvided_UsesIntakeUrl() - { - var source = new NameValueConfigurationSource(new NameValueCollection - { - { ConfigurationKeys.Telemetry.Enabled, "1" }, - { ConfigurationKeys.ApiKey, "some_key" }, - }); - - var settings = TelemetrySettings.FromSource(source); - settings.Agentless.Should().NotBeNull(); - settings.Agentless.AgentlessUri.Should().Be(DefaultIntakeUrl); - settings.ConfigurationError.Should().BeNullOrEmpty(); - } - - [Fact] - public void WhenApiKeyAndDdSiteIsProvided_UsesDdSiteDomain() - { - var domain = "my-domain.net"; - var source = new NameValueConfigurationSource(new NameValueCollection - { - { ConfigurationKeys.Telemetry.Enabled, "1" }, - { ConfigurationKeys.ApiKey, "some_key" }, - { ConfigurationKeys.Site, domain }, - }); - - var settings = TelemetrySettings.FromSource(source); - - settings.Agentless.Should().NotBeNull(); - settings.Agentless.AgentlessUri.Should().Be($"https://instrumentation-telemetry-intake.{domain}/"); - settings.ConfigurationError.Should().BeNullOrEmpty(); - } - - [Fact] - public void WhenInvalidUrlIsProvided_AndNoApiKey_AgentlessIsNotEnabled() - { - var url = "https://sometest::"; - var source = new NameValueConfigurationSource(new NameValueCollection - { - { ConfigurationKeys.Telemetry.Enabled, "1" }, - { ConfigurationKeys.Telemetry.Uri, url }, - }); - - var settings = TelemetrySettings.FromSource(source); - - settings.Agentless.Should().BeNull(); - settings.ConfigurationError.Should().BeNullOrEmpty(); - } - - [Theory] - [InlineData("https://sometest::")] - [InlineData("https://sometest:-1/")] - [InlineData("some-path/")] - [InlineData("nada")] - public void WhenInvalidUrlIsProvided_AndHasApiKey_UsesDefaultIntakeUrl(string url) - { - var source = new NameValueConfigurationSource(new NameValueCollection - { - { ConfigurationKeys.Telemetry.Enabled, "1" }, - { ConfigurationKeys.Telemetry.Uri, url }, - { ConfigurationKeys.ApiKey, "some_key" }, - }); - - var settings = TelemetrySettings.FromSource(source); - - settings.Agentless.Should().NotBeNull(); - settings.Agentless.AgentlessUri.Should().Be(DefaultIntakeUrl); - settings.ConfigurationError.Should().NotBeNullOrEmpty(); - } - - [Theory] - [InlineData(null, null, false)] - [InlineData("SOMEKEY", null, true)] - [InlineData(null, "0", false)] - [InlineData("SOMEKEY", "0", false)] - [InlineData(null, "1", true)] - [InlineData("SOMEKEY", "1", true)] - public void SetsTelemetryEnabledBasedOnApiKeyAndEnabledSettings(string apiKey, string enabledSetting, bool enabled) - { - var source = new NameValueConfigurationSource(new NameValueCollection - { - { ConfigurationKeys.Telemetry.Enabled, enabledSetting }, - { ConfigurationKeys.ApiKey, apiKey }, - }); - - var settings = TelemetrySettings.FromSource(source); - var expectAgentless = enabled && !string.IsNullOrEmpty(apiKey); - - if (expectAgentless) - { - settings.Agentless.Should().NotBeNull(); - } - else - { - settings.Agentless.Should().BeNull(); - } - - settings.TelemetryEnabled.Should().Be(enabled); - settings.ConfigurationError.Should().BeNullOrEmpty(); - } - - [Theory] - [InlineData(null, null)] - [InlineData(null, true)] - [InlineData(null, false)] - [InlineData("SOMEKEY", true)] - [InlineData("SOMEKEY", false)] - public void SetsAgentlessBasedOnApiKey(string apiKey, bool? agentless) - { - var source = new NameValueConfigurationSource(new NameValueCollection - { - { ConfigurationKeys.Telemetry.AgentlessEnabled, agentless?.ToString() }, - { ConfigurationKeys.ApiKey, apiKey }, - }); - var hasApiKey = !string.IsNullOrEmpty(apiKey); - - var settings = TelemetrySettings.FromSource(source); - using var s = new AssertionScope(); - - if (agentless == true) - { - settings.TelemetryEnabled.Should().Be(hasApiKey); - if (hasApiKey) - { - settings.Agentless.Should().NotBeNull(); - settings.ConfigurationError.Should().BeNullOrEmpty(); - } - else - { - settings.Agentless.Should().BeNull(); - settings.ConfigurationError.Should().NotBeNullOrEmpty(); - } - } - else if (agentless == false) - { - settings.Agentless.Should().BeNull(); - settings.TelemetryEnabled.Should().Be(false); - settings.ConfigurationError.Should().BeNullOrEmpty(); - } - else - { - if (hasApiKey) - { - settings.Agentless.Should().NotBeNull(); - } - else - { - settings.Agentless.Should().BeNull(); - } - - settings.TelemetryEnabled.Should().Be(hasApiKey); - settings.ConfigurationError.Should().BeNullOrEmpty(); - } - } - - [Theory] - [InlineData(null, null)] - [InlineData(null, true)] - [InlineData(null, false)] - [InlineData(false, null)] - [InlineData(false, true)] - [InlineData(false, false)] - [InlineData(true, null)] - [InlineData(true, true)] - [InlineData(true, false)] - public void SetsAgentlessBasedOnEnabledAndAgentlessEnabled(bool? enabled, bool? agentlessEnabled) - { - var source = new NameValueConfigurationSource(new NameValueCollection - { - { ConfigurationKeys.Telemetry.Enabled, enabled?.ToString() }, - { ConfigurationKeys.Telemetry.AgentlessEnabled, agentlessEnabled?.ToString() }, - { ConfigurationKeys.ApiKey, agentlessEnabled == true ? "SOME_KEY" : null }, - }); - - var settings = TelemetrySettings.FromSource(source); - - var expectEnabled = enabled == true || (enabled is null && agentlessEnabled == true); - var expectAgentless = expectEnabled && agentlessEnabled == true; - - settings.TelemetryEnabled.Should().Be(expectEnabled); - if (expectAgentless) - { - settings.Agentless.Should().NotBeNull(); - } - else - { - settings.Agentless.Should().BeNull(); - } - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Telemetry/Transports/JsonTelemetryTransportTests.cs b/tracer/test/Datadog.Trace.Tests/Telemetry/Transports/JsonTelemetryTransportTests.cs deleted file mode 100644 index 98de82273..000000000 --- a/tracer/test/Datadog.Trace.Tests/Telemetry/Transports/JsonTelemetryTransportTests.cs +++ /dev/null @@ -1,92 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System.Collections.Generic; -using System.IO; -using System.Threading.Tasks; -using Datadog.Trace.Telemetry; -using Datadog.Trace.Telemetry.Transports; -using Datadog.Trace.Vendors.Newtonsoft.Json.Linq; -using FluentAssertions; -using Xunit; - -namespace Datadog.Trace.Tests.Telemetry.Transports -{ - public class JsonTelemetryTransportTests - { - [Fact] - public async Task SerializeTelemetryShouldProduceJsonWithExpectedFormat() - { - var transport = new TestJsonTelemetryTransport(); - var expectedJson = JToken.Parse(GetSampleTelemetryData()); - - var data = new TelemetryData( - requestType: "app-started", - runtimeId: "20338dfd-f700-4e5c-b3f6-0d470f054ae8", - seqId: 5672, - tracerTime: 1628099086, - application: new ApplicationTelemetryData( - serviceName: "myapp", - env: "prod", - tracerVersion: "0.33.1", - languageName: "node.js", - languageVersion: "14.16.1") - { - ServiceVersion = "1.2.3", - }, - host: new HostTelemetryData - { - Hostname = "i-09ecf74c319c49be8", - ContainerId = "d39b145254d1f9c337fdd2be132f6650c6f5bc274bfa28aaa204a908a1134096", - Os = "GNU/Linux", - OsVersion = "ubuntu 18.04.5 LTS (Bionic Beaver)", - KernelName = "Linux", - KernelRelease = "5.4.0-1037-gcp", - KernelVersion = "#40~18.04.1-Ubuntu SMP Fri Feb 5 15:41:35 UTC 2021" - }, - payload: new AppStartedPayload( - integrations: new List - { - new(name: "express", enabled: true) { AutoEnabled = true }, - new(name: "pg", enabled: false) { AutoEnabled = false, Compatible = false }, - }, - dependencies: new List - { - new(name: "express") { Version = "8.6.0" }, - new(name: "express") { Version = "4.17.1" }, - new(name: "body-parser") { Version = "1.19.0" }, - }, - configuration: new List()) - { - AdditionalPayload = new List { new(name: "to_be", value: "determined") } - }); - - await transport.PushTelemetry(data); - transport.SerializedData.Should().NotBeNullOrEmpty(); - var actualJson = JToken.Parse(transport.SerializedData); - - actualJson.Should().BeEquivalentTo(expectedJson); - } - - private static string GetSampleTelemetryData() - { - var thisAssembly = typeof(JsonTelemetryTransportTests).Assembly; - var stream = thisAssembly.GetManifestResourceStream("Datadog.Trace.Tests.Telemetry.telemetry_data.json"); - using var streamReader = new StreamReader(stream); - return streamReader.ReadToEnd(); - } - - internal class TestJsonTelemetryTransport : ITelemetryTransport - { - public string SerializedData { get; private set; } - - public Task PushTelemetry(TelemetryData data) - { - SerializedData = JsonTelemetryTransport.SerializeTelemetry(data); - return Task.FromResult(TelemetryPushResult.Success); - } - } - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Telemetry/telemetry_data.json b/tracer/test/Datadog.Trace.Tests/Telemetry/telemetry_data.json deleted file mode 100644 index c773f8bcf..000000000 --- a/tracer/test/Datadog.Trace.Tests/Telemetry/telemetry_data.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "api_version": "v1", - "request_type": "app-started", - "tracer_time": 1628099086, - "runtime_id": "20338dfd-f700-4e5c-b3f6-0d470f054ae8", - "seq_id": 5672, - "application": { - "service_name": "myapp", - "env": "prod", - "tracer_version": "0.33.1", - "language_name": "node.js", - "service_version": "1.2.3", - "language_version": "14.16.1" - }, - "host": { - "hostname": "i-09ecf74c319c49be8", - "container_id": "d39b145254d1f9c337fdd2be132f6650c6f5bc274bfa28aaa204a908a1134096", - "os": "GNU/Linux", - "os_version": "ubuntu 18.04.5 LTS (Bionic Beaver)", - "kernel_name": "Linux", - "kernel_release": "5.4.0-1037-gcp", - "kernel_version": "#40~18.04.1-Ubuntu SMP Fri Feb 5 15:41:35 UTC 2021" - }, - "payload": { - "integrations": [ - { - "name": "express", - "enabled": true, - "auto_enabled": true - }, - { - "name": "pg", - "compatible": "false", - "enabled": false, - "auto_enabled": false - } - ], - "dependencies": [ - { - "name": "pg", - "version": "8.6.0" - }, - { - "name": "express", - "version": "4.17.1" - }, - { - "name": "body-parser", - "version": "1.19.0" - } - ], - "configuration": [], - "additional_payload": [ - { - "name": "to_be", - "value": "determined" - } - ] - } -} diff --git a/tracer/test/Datadog.Trace.Tests/Util/ModuleInitializer.cs b/tracer/test/Datadog.Trace.Tests/Util/ModuleInitializer.cs deleted file mode 100644 index 511fed90a..000000000 --- a/tracer/test/Datadog.Trace.Tests/Util/ModuleInitializer.cs +++ /dev/null @@ -1,21 +0,0 @@ -// -// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. -// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. -// - -using System; -using System.Runtime.CompilerServices; -using Datadog.Trace.Configuration; - -namespace Datadog.Trace.Tests.Util -{ - public class ModuleInitializer - { - [ModuleInitializer] - public static void Initialize() - { - // disable telemetry for any tests which create a "real" telemetry instance - Environment.SetEnvironmentVariable(ConfigurationKeys.Telemetry.Enabled, "false"); - } - } -}