Skip to content

Add documention for instrumenting Go function with OpenTelemetry #396

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

welteki
Copy link
Member

@welteki welteki commented May 13, 2025

Description

Add instructions on how to instrument Gofunctions with OpenTelemetry

Motivation and Context

  • I have raised an issue to propose this change (required)

Show how OpenTelemetry can be used with OpenFaaS.

How Has This Been Tested?

Verified the modified template is working and traces can be viewed.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have signed-off my commits with git commit -s

Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
@welteki welteki changed the title Go instrumentation Add documention for instrumenting Go function with OpenTelemetry May 13, 2025

```go
func newTracerProvider(exporters []sdktrace.SpanExporter) *sdktrace.TracerProvider {
serviceName := os.Getenv("OTEL_SERVICE_NAME")
Copy link
Member

Choose a reason for hiding this comment

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

Isn't there a FUNCTION_NAME?


input = body
}

Copy link
Member

Choose a reason for hiding this comment

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

Can you create a method i.e. "callOpenAI" - make it wait 2 seconds, create a separate span for it?

}

w.WriteHeader(http.StatusOK)
w.Write([]byte(fmt.Sprintf("Body: %s", 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.

fmt.Fprintf(w, "Hello, World!")

Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
@welteki welteki force-pushed the go-instrumentation branch from 9465b04 to 9dde253 Compare May 19, 2025 08:29
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