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

OpenTelemetry instrumentation example #296

Merged
merged 37 commits into from
Jan 16, 2024

Conversation

emanuelef
Copy link
Contributor

@emanuelef emanuelef commented Jul 13, 2023

What was changed

Added example to show how to instrument OpenTelemetry in the worker and client

Why?

Currently there is no sample to show how to instrument a Temporal worker and a client with OpenTelemetry.
This can save some time and clarifies what is the minimum needed to be able to export traces.

There's also an open issue:
#269

Checklist

  1. Closes

  2. How was this tested:

Run as most of the samples, no need to set OTLP endpoint and see the spans in the stdout.
Also tested with Honeycomb.io.

  1. Any docs updates needed?

Updated README.md

@emanuelef emanuelef marked this pull request as draft July 13, 2023 06:27
@emanuelef emanuelef marked this pull request as ready for review July 13, 2023 21:04
otel/README.md Outdated Show resolved Hide resolved
otel/README.md Outdated Show resolved Hide resolved
otel/README.md Outdated Show resolved Hide resolved
otel/README.md Outdated Show resolved Hide resolved
otel/README.md Outdated Show resolved Hide resolved
otel/otel.go Outdated Show resolved Hide resolved
"go.temporal.io/sdk/client"
"go.temporal.io/sdk/interceptor"

otelworkflow "github.com/temporalio/samples-go/otel"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
otelworkflow "github.com/temporalio/samples-go/otel"
"github.com/temporalio/samples-go/otel"

No need for package alias and doesn't seem purely about workflows

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it will now clash with "go.temporal.io/sdk/contrib/opentelemetry"

log.Fatalln("Unable to execute workflow", err)
}

log.Println("Started workflow", "WorkflowID", we.GetID(), "RunID", we.GetRunID())
Copy link
Member

Choose a reason for hiding this comment

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

The standard Go logger doesn't usually expect key-value pair type logs like structured logging does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

👍 We get it wrong in those too, oh well. Can ignore.

otel/otel-setup.go Outdated Show resolved Hide resolved
otel/starter/main.go Outdated Show resolved Hide resolved
@cretz
Copy link
Member

cretz commented Jul 13, 2023

Thanks! Looks great, just added some comments.

@emanuelef emanuelef requested a review from cretz July 14, 2023 05:20
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.

Looks good! I think we can just drop the JSON and I'll merge. Thanks for the help here!

@emanuelef emanuelef requested a review from cretz July 14, 2023 20:06
@cretz
Copy link
Member

cretz commented Jul 14, 2023

@emanuelef - I think you may need a go mod tidy run from the repo root

@emanuelef
Copy link
Contributor Author

emanuelef commented Jul 15, 2023

When I do I get:

go: finding module for package go.temporal.io/server/tools/cli/plugin
github.com/temporalio/samples-go/snappycompress/plugin imports
        go.temporal.io/server/tools/cli/plugin: module go.temporal.io/server@latest found (v1.21.2), but does not contain package go.temporal.io/server/tools/cli/plugin

@emanuelef emanuelef requested a review from cretz July 15, 2023 09:35
@cretz
Copy link
Member

cretz commented Jul 17, 2023

I think this is because you inadvertently updated API and server. Try to set go.temporal.io/api and go.temporal.io/server back to what they are in main's go.mod manually (I guess go.temporal.io/api v1.7.1-0.20220131203817-08fe71b1361d and go.temporal.io/server v1.15.2), then run go mod tidy. Otherwise, we can open another PR to update server (looks like some packages moved around in there).

@cretz
Copy link
Member

cretz commented Jul 24, 2023

If OpenTelemetry sample cannot be added without updating server, I am afraid this is going to have to wait on #264 to be solved.

@emanuelef
Copy link
Contributor Author

If OpenTelemetry sample cannot be added without updating server, I am afraid this is going to have to wait on #264 to be solved.

Is this something expected to be done soon ?

@cretz
Copy link
Member

cretz commented Jul 31, 2023

I don't have a specific timeline, sorry

Quinn-With-Two-Ns and others added 14 commits January 3, 2024 21:00
* created batch-sliding-window

* renamed package

* Added activities and workflows

* Ported activities and workflows from Java

* sliding window progress

* simplistic test passes

* Failure to drain reproduction

* Added error handling to record_processor_workflow

* added sort

* Fixed batch partitions

* Added description to README

* Fixed nondeterminism errors
@emanuelef
Copy link
Contributor Author

emanuelef commented Jan 9, 2024

@Quinn-With-Two-Ns can you have a look ? With the latest changes the tests (when running locally with make test) are passing.
The open telemetry example is running as well.
But I'm still having errors reported on grpc-proxy and codec-server due to the following imported modules:
go.temporal.io/server/common/authorization
go.temporal.io/server/common/config

Thanks

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.

Looks mostly good, we need to get CI working though

README.md Outdated Show resolved Hide resolved
go.mod Outdated
github.com/pborman/uuid v1.2.1
github.com/prometheus/client_golang v1.16.0
Copy link
Member

Choose a reason for hiding this comment

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

Hrmm, wonder why this got removed. I think CI is failing here, may need a go mod tidy

Copy link
Contributor Author

@emanuelef emanuelef Jan 12, 2024

Choose a reason for hiding this comment

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

This is present as indirect: https://github.com/emanuelef/samples-go/blob/598b901b62e521741e3a78a27f071abcdc2188f9/go.mod#L52C1-L52C1

Tried to run go mod tidy anyway and got:

go: github.com/temporalio/samples-go/codec-server/codec-server imports
        go.temporal.io/server/common/config imports
        go.temporal.io/server/common/telemetry imports
        go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc imports
        go.opentelemetry.io/otel/exporters/otlp/internal: module go.opentelemetry.io/otel/exporters/otlp@latest found (v0.20.1), but does not contain package go.opentelemetry.io/otel/exporters/otlp/internal
go: github.com/temporalio/samples-go/codec-server/codec-server imports
        go.temporal.io/server/common/config imports
        go.temporal.io/server/common/telemetry imports
        go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc imports
        go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal/oconf imports
        go.opentelemetry.io/otel/exporters/otlp/internal/envconfig: module go.opentelemetry.io/otel/exporters/otlp@latest found (v0.20.1), but does not contain package go.opentelemetry.io/otel/exporters/otlp/internal/envconfig

Copy link
Member

@cretz cretz Jan 12, 2024

Choose a reason for hiding this comment

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

go mod tidy has to work on our samples. It appears that our server expects an older version of go.opentelemetry.io/otel (https://github.com/temporalio/temporal/blob/v1.22.3/go.mod#L39). I think if you put to go.mod back as it was and just add that version of otel and then go mod tidy it should figure it out. You may have to work with it. But you can't do a go get -u or similar overall because it updated lots of unrelated dependencies here I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed and now go mod tidy doesn't complain, thanks.

opentelemetry/worker/main.go Outdated Show resolved Hide resolved
opentelemetry/worker/main.go Outdated Show resolved Hide resolved
emanuelef and others added 5 commits January 12, 2024 04:58
Co-authored-by: Chad Retz <chad.retz@gmail.com>
Co-authored-by: Chad Retz <chad.retz@gmail.com>
Co-authored-by: Chad Retz <chad.retz@gmail.com>
@emanuelef emanuelef requested a review from cretz January 12, 2024 15:43
@emanuelef
Copy link
Contributor Author

@cretz ci-build is now passing

@Quinn-With-Two-Ns Quinn-With-Two-Ns merged commit 2590097 into temporalio:main Jan 16, 2024
4 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.

7 participants