public AspNetCoreHttpRequestHandler(
     IDatadogLogger log,
     string requestInOperationName,
     IntegrationId integrationInfo)
 {
     _log                    = log;
     _integrationId          = integrationInfo;
     _requestInOperationName = requestInOperationName;
 }
예제 #2
0
 public Api(
     IApiRequestFactory apiRequestFactory,
     IDogStatsd statsd,
     Action <Dictionary <string, float> > updateSampleRates,
     bool isPartialFlushEnabled,
     IDatadogLogger log = null)
 {
     // optionally injecting a log instance in here for testing purposes
     _log = log ?? StaticLog;
     _log.Debug("Creating new Api");
     _updateSampleRates     = updateSampleRates;
     _statsd                = statsd;
     _containerId           = ContainerMetadata.GetContainerId();
     _apiRequestFactory     = apiRequestFactory;
     _isPartialFlushEnabled = isPartialFlushEnabled;
     _tracesEndpoint        = _apiRequestFactory.GetEndpoint(TracesPath);
     _log.Debug("Using traces endpoint {TracesEndpoint}", _tracesEndpoint.ToString());
 }
예제 #3
0
        public static void ErrorRetrievingMethod(
            this IDatadogLogger logger,
            Exception exception,
            long moduleVersionPointer,
            int mdToken,
            int opCode,
            string instrumentedType,
            string methodName,
            string instanceType                = null,
            string[] relevantArguments         = null,
            [CallerLineNumber] int sourceLine  = 0,
            [CallerFilePath] string sourceFile = "")
        {
            var instrumentedMethod = $"{instrumentedType}.{methodName}(...)";

            if (instanceType != null)
            {
                instrumentedMethod = $"{instrumentedMethod} on {instanceType}";
            }

            if (relevantArguments != null)
            {
                instrumentedMethod = $"{instrumentedMethod} with {string.Join(", ", relevantArguments)}";
            }

            var moduleVersionId = PointerHelpers.GetGuidFromNativePointer(moduleVersionPointer);

            // ReSharper disable twice ExplicitCallerInfoArgument
            logger.Error(
                exception,
                $"Error (MVID: {moduleVersionId}, mdToken: {mdToken}, opCode: {opCode}) could not retrieve: {instrumentedMethod}",
                sourceLine,
                sourceFile);

            var statsd = Tracer.Instance.Statsd;

            if (statsd != null)
            {
                string[] tags = { $"instrumented-method:{instrumentedMethod}" };
                statsd.Exception(exception, source: instrumentedType, message: "Error retrieving instrumented method", tags);
            }
        }
 public static void TestClassTypeNotFound(this IDatadogLogger logger, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "")
 {
     // ReSharper disable twice ExplicitCallerInfoArgument
     logger.Error("Error: the test class type can't be retrieved.", sourceLine, sourceFile);
 }
        static DatadogLogging()
        {
            // No-op for if we fail to construct the file logger
            var     nullRateLimiter = new NullLogRateLimiter();
            ILogger internalLogger  = new LoggerConfiguration()
                                      .WriteTo.Sink <NullSink>()
                                      .CreateLogger();

            SharedLogger = new DatadogSerilogLogger(internalLogger, nullRateLimiter);

            try
            {
                if (GlobalSettings.Source.DebugEnabled)
                {
                    LoggingLevelSwitch.MinimumLevel = LogEventLevel.Debug;
                }

                var maxLogSizeVar = EnvironmentHelpers.GetEnvironmentVariable(ConfigurationKeys.MaxLogFileSize);
                if (long.TryParse(maxLogSizeVar, out var maxLogSize))
                {
                    // No verbose or debug logs
                    MaxLogFileSize = maxLogSize;
                }

                string logDirectory = null;
                try
                {
                    logDirectory = GetLogDirectory();
                }
                catch
                {
                    // Do nothing when an exception is thrown for attempting to access the filesystem
                }

                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                if (logDirectory == null)
                {
                    return;
                }

                var domainMetadata = DomainMetadata.Instance;

                // Ends in a dash because of the date postfix
                var managedLogPath = Path.Combine(logDirectory, $"dotnet-tracer-managed-{domainMetadata.ProcessName}-.log");

                var loggerConfiguration =
                    new LoggerConfiguration()
                    .Enrich.FromLogContext()
                    .MinimumLevel.ControlledBy(LoggingLevelSwitch)
                    .WriteTo.File(
                        managedLogPath,
                        outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj} {Exception} {Properties}{NewLine}",
                        rollingInterval: RollingInterval.Day,
                        rollOnFileSizeLimit: true,
                        fileSizeLimitBytes: MaxLogFileSize,
                        shared: true);

                try
                {
                    loggerConfiguration.Enrich.WithProperty("MachineName", domainMetadata.MachineName);
                    loggerConfiguration.Enrich.WithProperty("Process", $"[{domainMetadata.ProcessId} {domainMetadata.ProcessName}]");
                    loggerConfiguration.Enrich.WithProperty("AppDomain", $"[{domainMetadata.AppDomainId} {domainMetadata.AppDomainName}]");
#if NETCOREAPP
                    loggerConfiguration.Enrich.WithProperty("AssemblyLoadContext", System.Runtime.Loader.AssemblyLoadContext.GetLoadContext(typeof(DatadogLogging).Assembly)?.ToString());
#endif
                    loggerConfiguration.Enrich.WithProperty("TracerVersion", TracerConstants.AssemblyVersion);
                }
                catch
                {
                    // At all costs, make sure the logger works when possible.
                }

                internalLogger = loggerConfiguration.CreateLogger();
                SharedLogger   = new DatadogSerilogLogger(internalLogger, nullRateLimiter);

                var             rate        = GetRateLimit();
                ILogRateLimiter rateLimiter = rate == 0
                    ? nullRateLimiter
                    : new LogRateLimiter(rate);

                SharedLogger = new DatadogSerilogLogger(internalLogger, rateLimiter);
            }
            catch
            {
                // Don't let this exception bubble up as this logger is for debugging and is non-critical
            }
        }
예제 #6
0
 public static void TestClassTypeNotFound(this IDatadogLogger logger, [CallerLineNumber] int sourceLine = 0, [CallerFilePath] string sourceFile = "")
 {
     logger.Error("Error: the test class type can't be retrieved.", sourceLine, sourceFile);
 }
 private void WriteRateLimitedLogMessage(IDatadogLogger logger, string message)
 => logger.Warning(message);
 public EventMessagePackFormatter()
 {
     _log = DatadogLogging.GetLoggerFor(GetType());
 }
        public static TraceId ParseTraceId <T>(T carrier, Func <T, string, IEnumerable <string> > getter, string headerName, ITraceIdConvention traceIdConvention, IDatadogLogger logger)
        {
            var headerValues = getter(carrier, headerName) ?? Enumerable.Empty <string>();
            var hasValue     = false;

            foreach (var headerValue in headerValues)
            {
                var traceId = traceIdConvention.CreateFromString(headerValue);
                if (traceId == TraceId.Zero)
                {
                    hasValue = true;
                    continue;
                }

                return(traceId);
            }

            if (hasValue)
            {
                logger.Warning("Could not parse {HeaderName} headers: {HeaderValues}", headerName, string.Join(",", headerValues));
            }

            return(TraceId.Zero);
        }