Exemplo n.º 1
0
        public LogFormatterTests()
        {
            var settings = ImmutableDirectLogSubmissionSettings.Create(
                host: Host,
                source: Source,
                intakeUrl: "http://localhost",
                apiKey: "some_value",
                minimumLevel: DirectSubmissionLogLevel.Debug,
                globalTags: new Dictionary <string, string> {
                { "Key1", "Value1" }, { "Key2", "Value2" }
            },
                enabledLogShippingIntegrations: new List <string> {
                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);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ImmutableTracerSettings"/> class from
        /// a TracerSettings instance.
        /// </summary>
        /// <param name="settings">The tracer settings to use to populate the immutable tracer settings</param>
        public ImmutableTracerSettings(TracerSettings settings)
        {
            Environment      = settings.Environment;
            ServiceName      = settings.ServiceName;
            ServiceVersion   = settings.ServiceVersion;
            TraceEnabled     = settings.TraceEnabled;
            ExporterSettings = new ImmutableExporterSettings(settings.ExporterSettings);
            TracesTransport  = settings.TracesTransport;
#pragma warning disable 618 // App analytics is deprecated, but still used
            AnalyticsEnabled = settings.AnalyticsEnabled;
#pragma warning restore 618
            MaxTracesSubmittedPerSecond = settings.MaxTracesSubmittedPerSecond;
            CustomSamplingRules         = settings.CustomSamplingRules;
            GlobalSamplingRate          = settings.GlobalSamplingRate;
            Integrations                      = new ImmutableIntegrationSettingsCollection(settings.Integrations, settings.DisabledIntegrationNames);
            GlobalTags                        = new ReadOnlyDictionary <string, string>(settings.GlobalTags);
            HeaderTags                        = new ReadOnlyDictionary <string, string>(settings.HeaderTags);
            GrpcTags                          = new ReadOnlyDictionary <string, string>(settings.GrpcTags);
            TracerMetricsEnabled              = settings.TracerMetricsEnabled;
            RuntimeMetricsEnabled             = settings.RuntimeMetricsEnabled;
            KafkaCreateConsumerScopeEnabled   = settings.KafkaCreateConsumerScopeEnabled;
            StartupDiagnosticLogEnabled       = settings.StartupDiagnosticLogEnabled;
            HttpClientExcludedUrlSubstrings   = settings.HttpClientExcludedUrlSubstrings;
            HttpServerErrorStatusCodes        = settings.HttpServerErrorStatusCodes;
            HttpClientErrorStatusCodes        = settings.HttpClientErrorStatusCodes;
            ServiceNameMappings               = settings.ServiceNameMappings;
            TraceBufferSize                   = settings.TraceBufferSize;
            TraceBatchInterval                = settings.TraceBatchInterval;
            RouteTemplateResourceNamesEnabled = settings.RouteTemplateResourceNamesEnabled;
            DelayWcfInstrumentationEnabled    = settings.DelayWcfInstrumentationEnabled;
            TraceMethods                      = settings.TraceMethods;
            IsActivityListenerEnabled         = settings.IsActivityListenerEnabled;

            TagMongoCommands           = settings.TagMongoCommands;
            TagRedisCommands           = settings.TagRedisCommands;
            TagElasticsearchQueries    = settings.TagElasticsearchQueries;
            TraceResponseHeaderEnabled = settings.TraceResponseHeaderEnabled;
            RecordedValueMaxLength     = settings.RecordedValueMaxLength;
            SignalFxAccessToken        = settings.SignalFxAccessToken;
            Convention = settings.Convention;
            Exporter   = settings.Exporter;

            ThreadSamplingEnabled = settings.ThreadSamplingEnabled;
            ThreadSamplingPeriod  = settings.ThreadSamplingPeriod;
            LogSubmissionSettings = ImmutableDirectLogSubmissionSettings.Create(settings.LogSubmissionSettings);
            // Logs injection is enabled by default if direct log submission is enabled, otherwise disabled by default
            LogsInjectionEnabled = settings.LogSubmissionSettings.LogsInjectionEnabled ?? LogSubmissionSettings.IsEnabled;

            PropagationStyleInject  = settings.PropagationStyleInject;
            PropagationStyleExtract = settings.PropagationStyleExtract;

            // we cached the static instance here, because is being used in the hotpath
            // by IsIntegrationEnabled method (called from all integrations)
            _domainMetadata = DomainMetadata.Instance;

            ExpandRouteTemplatesEnabled = settings.ExpandRouteTemplatesEnabled || !RouteTemplateResourceNamesEnabled;
        }
Exemplo n.º 3
0
 public LogFormatter(
     ImmutableDirectLogSubmissionSettings settings,
     string serviceName,
     string env,
     string version)
 {
     _source     = string.IsNullOrEmpty(settings.Source) ? null : settings.Source;
     _service    = string.IsNullOrEmpty(serviceName) ? null : serviceName;
     _host       = string.IsNullOrEmpty(settings.Host) ? null : settings.Host;
     _globalTags = string.IsNullOrEmpty(settings.GlobalTags) ? null : settings.GlobalTags;
     _env        = string.IsNullOrEmpty(env) ? null : env;
     _version    = string.IsNullOrEmpty(version) ? null : version;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImmutableTracerSettings"/> class from
        /// a TracerSettings instance.
        /// </summary>
        /// <param name="settings">The tracer settings to use to populate the immutable tracer settings</param>
        public ImmutableTracerSettings(TracerSettings settings)
        {
            Environment    = settings.Environment;
            ServiceName    = settings.ServiceName;
            ServiceVersion = settings.ServiceVersion;
            TraceEnabled   = settings.TraceEnabled;
            Exporter       = new ImmutableExporterSettings(settings.Exporter);
#pragma warning disable 618 // App analytics is deprecated, but still used
            AnalyticsEnabled = settings.AnalyticsEnabled;
#pragma warning restore 618
            LogsInjectionEnabled        = settings.LogsInjectionEnabled;
            MaxTracesSubmittedPerSecond = settings.MaxTracesSubmittedPerSecond;
            CustomSamplingRules         = settings.CustomSamplingRules;
            GlobalSamplingRate          = settings.GlobalSamplingRate;
            Integrations                      = new ImmutableIntegrationSettingsCollection(settings.Integrations, settings.DisabledIntegrationNames);
            GlobalTags                        = new ReadOnlyDictionary <string, string>(settings.GlobalTags);
            HeaderTags                        = new ReadOnlyDictionary <string, string>(settings.HeaderTags);
            TracerMetricsEnabled              = settings.TracerMetricsEnabled;
            RuntimeMetricsEnabled             = settings.RuntimeMetricsEnabled;
            KafkaCreateConsumerScopeEnabled   = settings.KafkaCreateConsumerScopeEnabled;
            StartupDiagnosticLogEnabled       = settings.StartupDiagnosticLogEnabled;
            HttpClientExcludedUrlSubstrings   = settings.HttpClientExcludedUrlSubstrings;
            HttpServerErrorStatusCodes        = settings.HttpServerErrorStatusCodes;
            HttpClientErrorStatusCodes        = settings.HttpClientErrorStatusCodes;
            ServiceNameMappings               = settings.ServiceNameMappings;
            TraceBufferSize                   = settings.TraceBufferSize;
            TraceBatchInterval                = settings.TraceBatchInterval;
            RouteTemplateResourceNamesEnabled = settings.RouteTemplateResourceNamesEnabled;
            DelayWcfInstrumentationEnabled    = settings.DelayWcfInstrumentationEnabled;
            PropagationStyleInject            = settings.PropagationStyleInject;
            PropagationStyleExtract           = settings.PropagationStyleExtract;

            LogSubmissionSettings = ImmutableDirectLogSubmissionSettings.Create(settings.LogSubmissionSettings);

            // we cached the static instance here, because is being used in the hotpath
            // by IsIntegrationEnabled method (called from all integrations)
            _domainMetadata = DomainMetadata.Instance;

            ExpandRouteTemplatesEnabled = settings.ExpandRouteTemplatesEnabled || !RouteTemplateResourceNamesEnabled;
        }