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

Add OpenTelemetry Sample #78

Merged
merged 7 commits into from
Sep 3, 2024
Merged

Add OpenTelemetry Sample #78

merged 7 commits into from
Sep 3, 2024

Conversation

robcao
Copy link
Contributor

@robcao robcao commented Jul 24, 2024

What was changed

Added OpenTelemetry sample.

Why?

It was missing and requested.

Checklist

  1. Closes
    Sample request: OpenTelemetry #67

  2. How was this tested:

Added screenshots similar to the python sample

  1. Any docs updates needed?


using var meter = new Meter(assemblyName.Name!, assemblyName.Version!.ToString());

string instanceId = args.ElementAtOrDefault(0) ?? throw new ArgumentException("Must pass 'worker' or 'workflow' as the single argument");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A little bit of repetition here, but it matters greatly for the OpenTelemetry sample in terms of correlating telemetry coming from the worker or client.

aspire-dashboard:
environment:
Dashboard__Frontend__AuthMode: Unsecured
image: mcr.microsoft.com/dotnet/aspire-dashboard:8.0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did see that the python samples are using the Jaeger image and not the Aspire Dashboard, which is developed by Microsoft: https://github.com/temporalio/samples-python/tree/main/open_telemetry

I can change to the Jaeger image if desired.

The main benefit of using the Aspire dashboard over Jaeger is that it provides visualizations for metrics, which iirc Jaeger does not. I think using a Microsoft image is probably okay specifically for .NET

Copy link
Member

@cretz cretz Jul 25, 2024

Choose a reason for hiding this comment

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

I don't mind this, I like the metrics, so I think this image is great. Alternatively, you can get rid of docker compose and just tell people how to start the this docker container directly in the README, but this is fine too.

Copy link
Contributor Author

@robcao robcao Jul 30, 2024

Choose a reason for hiding this comment

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

Imo, docker compose is easier with a single command, since environment variables and port forwarding are involved

Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

This is great, thanks! Just some minor things, but overall LGTM

README.md Outdated Show resolved Hide resolved
src/OpenTelemetry/MyWorkflow.workflow.cs Outdated Show resolved Hide resolved
{
Metrics = new MetricsOptions()
{
CustomMetricMeter = new CustomMetricMeter(meter),
Copy link
Member

Choose a reason for hiding this comment

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

Hrmm, so there are two ways to configure OTel telemetry metrics. One way is this, but the other way is simply to set the OTel options in this metric options so our internal code forwards. We often encourage the latter because it's less setup and it matches other SDKs.

I wonder if there is some way we can show both? Like maybe switched from one to the other via CLI flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I split this into two samples, OpenTelemetry/CoreSdkFowarding and OpenTelemetry/DotNetMetrics.

I thought this was cleanest, and follows a similar pattern that exists with the polling samples

Copy link
Member

@cretz cretz Aug 5, 2024

Choose a reason for hiding this comment

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

Ok, will look. Alternatively we probably could have just had a different parameter accepted in the Program.cs to choose one approach or the other instead of completely separate projects.

public static class Activities
{
[Activity]
public static void MyActivity(string input)
Copy link
Member

Choose a reason for hiding this comment

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

I think it'd be valuable here and in workflow to show a custom metric. E.g. ActivityExecutionContext.Current.MetricMeter.CreateCounter<int>("my-counter").Add(123) and Workflow.MetricMeter.CreateCounter<int>("my-counter").Add(123). Technically you could instantiate the activity class with the .NET mertic meter, but this way respects the existing abstraction (so you don't have to have custom meter), and for workflows you can't inject anything and it's a replay-safe metric meter (i.e. it doesn't record on replay).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

src/OpenTelemetry/Program.cs Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Is this file needed? We don't usually add to the rest of our samples

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not needed, removed.

launchSettings are a convenience that popular .NET IDEs such as Rider, VS, and VSCode support that allow developers to pre-configure executables launched directly in the IDE with command line arguments, environment variables, etc

aspire-dashboard:
environment:
Dashboard__Frontend__AuthMode: Unsecured
image: mcr.microsoft.com/dotnet/aspire-dashboard:8.0
Copy link
Member

@cretz cretz Jul 25, 2024

Choose a reason for hiding this comment

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

I don't mind this, I like the metrics, so I think this image is great. Alternatively, you can get rid of docker compose and just tell people how to start the this docker container directly in the README, but this is fine too.

src/OpenTelemetry/Activities.cs Outdated Show resolved Hide resolved
Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

Sorry it took so long to get back, I was OOO last week. Overall LGTM. Would like to have OTel tracing in both and I really, I think it's clearer to have just one project w/ metric config switched based on command line (if you can't choose which to default, make the CLI arg required to pick one, e.g. --dotnet-metrics and --core-metrics or something).

src/OpenTelemetry/CoreSdkForwarding/Program.cs Outdated Show resolved Hide resolved
src/OpenTelemetry/CoreSdkForwarding/README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
@cretz
Copy link
Member

cretz commented Sep 3, 2024

@robcao - assuming you don't mind, I am going to work in your branch to get this over the finish line. I think it may just be a matter of merging main (fixing conflicts) and a few extra things.

# Conflicts:
#	Directory.Build.props
#	README.md
#	TemporalioSamples.sln
@robcao
Copy link
Contributor Author

robcao commented Sep 3, 2024

@robcao - assuming you don't mind, I am going to work in your branch to get this over the finish line. I think it may just be a matter of merging main (fixing conflicts) and a few extra things.

Yeah, I don't mind.

Sorry about the unintentional abandonment of the pull request, I had meant to get back to it, but life just got in the way.

I don't mind collapsing the samples into a single project file. My original thought was that the two different techniques used to gather metrics have different dependencies, so that putting them together in the same project file makes it harder to understand the minimal set of dependencies, but I am ok either way.

@cretz
Copy link
Member

cretz commented Sep 3, 2024

Sorry about the unintentional abandonment of the pull request, I had meant to get back to it, but life just got in the way.

All good, I think we're ready for merge, thanks for the contribution!

I don't mind collapsing the samples into a single project file

I kept them separate for now, it works fine I think

@cretz cretz merged commit 6e8c6be into temporalio:main Sep 3, 2024
6 checks passed
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.

2 participants