Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Structured Logging in a More Structured Way #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Amazon.CloudWatch.EMF/Environment/ECSEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void CheckAndSetFluentHost()
_fluentBitEndpoint = string.Format("tcp://%s:%d", fluentHost, Constants.DEFAULT_AGENT_PORT);
_configuration.AgentEndPoint = _fluentBitEndpoint;

_logger.LogInformation("Using FluentBit configuration. Endpoint: {}", _fluentBitEndpoint);
_logger.LogInformation("Using FluentBit configuration. Endpoint: {Endpoint}", _fluentBitEndpoint);
}

private void FormatImageName()
Expand Down
2 changes: 1 addition & 1 deletion src/Amazon.CloudWatch.EMF/Logger/MetricsLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void Flush()
throw new InvalidOperationException(message);
}

_logger.LogDebug("Sending data to sink. {}", _environment.Sink.GetType().Name);
_logger.LogDebug("Sending data to sink: {SinkName}", _environment.Sink.GetType().Name);

_environment.Sink.Accept(_context);
_context = _context.CreateCopyWithContext();
Expand Down
6 changes: 3 additions & 3 deletions src/Amazon.CloudWatch.EMF/Sink/AgentSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ public void Accept(MetricsContext metricsContext)
}
catch (InvalidOperationException e)
{
_logger.LogError("Attempted to publish data after the sink has been shutdown. {}", e);
_logger.LogError(e, "Attempted to publish data after the sink has been shutdown.");
}

_logger.LogDebug("Data queued successfully.");
}
}
catch (Exception e)
{
_logger.LogError("Failed to serialize the metrics with the exception: {}", e);
_logger.LogError(e, "Failed to serialize the metrics.");
}
}

Expand Down Expand Up @@ -118,7 +118,7 @@ private Task RunSenderThread(ILoggerFactory loggerFactory)
}
catch (Exception e)
{
logger.LogWarning("Failed to write message to socket. Backing off and trying again. {}", e.Message);
logger.LogWarning(e, "Failed to write message to socket. Backing off and trying again.");
Thread.Sleep(1000); // TODO: backoff
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this shouldn't be:

await Task.Delay(TimeSpan.FromMilliseconds(1000)).ConfigureAwait(false);

…but that felt out of scope and like a Chesterton's Fence thing.

}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Amazon.CloudWatch.EMF/Sink/ConsoleSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void Accept(MetricsContext context)
}
catch (Exception e)
{
_logger.LogError("Failed to serialize a MetricsContext: {}", e);
_logger.LogError(e, "Failed to serialize a MetricsContext.");
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Amazon.CloudWatch.EMF/Sink/Endpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Endpoint(string url, ILoggerFactory loggerFactory)
}
catch (UriFormatException)
{
logger.LogWarning("Failed to parse the endpoint: {} ", url);
logger.LogWarning("Failed to parse the endpoint: {Url} ", url);
SetDefault();
}

Expand All @@ -51,7 +51,7 @@ public Endpoint(string url, ILoggerFactory loggerFactory)
catch (Exception)
{
logger.LogWarning(
"Unsupported protocol: {}. Would use default endpoint: {}",
"Unsupported protocol: {Url}. Would use default endpoint: {Endpoint}",
url,
DEFAULT_TCP_ENDPOINT);

Expand Down