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

Pare down the C# example a little #1

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

nblumhardt
Copy link
Member

This proposes a couple of possible updates for the C# example. I'll comment them all inline, they're definitely not all necessary, let me know what you think! :-)


ActivitySource ExampleWeatherServiceActivitySource = new("Example Weather Service");
var exampleActivitySource = new ActivitySource("Example.WeatherService");
Copy link
Member Author

Choose a reason for hiding this comment

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

Convention for activity source names is normally namespace-style.


try
Copy link
Member Author

Choose a reason for hiding this comment

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

Catch block is redundant, since allowing the exception to escape Main() will also produce a nonzero exit code, and have the side-effect of printing some useful output to stderr.

{
openTelemetryLoggerOptions.SetResourceBuilder(
ResourceBuilder.CreateEmpty()
.AddService(serviceName: builder.Environment.ApplicationName));
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed the example resource attributes; these are normally set through environment variables and other means (although adding them here is still valid).


app.MapGet("/{postcode}", (string postcode) =>
// Some important options to improve data quality
openTelemetryLoggerOptions.IncludeScopes = true;
Copy link
Member Author

Choose a reason for hiding this comment

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

Don't need IncludeFormattedMessage anymore, Seq will heuristically detect message templates.

{
return 1;
}
using var activity = exampleActivitySource.StartActivity("Look up forecast for postcode {Postcode}");
Copy link
Member Author

Choose a reason for hiding this comment

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

The suppressed warning at the top of the file is because we want to pass an activity name explicitly here.

@KodrAus KodrAus merged commit 2fe1759 into datalust:main Jan 18, 2024
@liammclennan
Copy link
Contributor

much better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants