Skip to content

Commit

Permalink
release(otel): Bump otel package to v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-welsch committed Feb 12, 2025
1 parent 4e4f2ae commit c101658
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
7 changes: 7 additions & 0 deletions otel/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

## To be released

## v0.1.0

- Initial version of the `otel` package to initialize the OpenTelemetry SDK to send metrics
44 changes: 31 additions & 13 deletions otel/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
# How to use
# Package `otel` v0.1.0

```go
## Usage

```go
package main

import (
"context"
"context"

otelsdk "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
sdkmetric "go.opentelemetry.io/otel/metric"

"github.com/Scalingo/go-utils/otel"
"github.com/kelseyhightower/envconfig"
"github.com/Scalingo/go-utils/otel"
)

func main() {
ctx := context.Background()
ctx := context.Background()

// Initialize OpenTelemetry SDK
shutdown, err := otel.Init(ctx)
if err != nil {
fmt.Printf("init otel: %v\n", err)
return
}
// Handle collection of metrics properly when service shut down
defer shutdown(ctx)

// Create a meter
meter := otelsdk.Meter("deployment")

// Initialize Otel
err := otel.New(ctx)
if err != nil {
return
}
// Create an instrument, based on the meter previously created
deploymentCount, err := meter.Int64Counter("deployment_count", sdkmetric.WithDescription("Number of deployments"))
if err != nil {
fmt.Printf("instrument creation failed: %v\n", err)
return
}

// Handle shutdown properly so nothing leaks.
defer otel.Shutdown(ctx)
// Create measurements on the instrument
deploymentCount.Add(ctx, 10, sdkmetric.WithAttributes(attribute.String("app_id", "caaaefb0-dcaa-4866-83d2-b581228169d8")))
deploymentCount.Add(ctx, 42, sdkmetric.WithAttributes(attribute.String("app_id", "caaaefb0-dcaa-4866-83d2-b581228169d8")))
}
```
3 changes: 0 additions & 3 deletions otel/otel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
otelsdk "go.opentelemetry.io/otel"
)

func TestInit(t *testing.T) {
Expand Down Expand Up @@ -57,8 +56,6 @@ func TestInit(t *testing.T) {
t.Cleanup(func() {
require.NoError(t, shutdown(ctx))
})

require.NotNil(t, otelsdk.GetMeterProvider())
}
})
}
Expand Down

0 comments on commit c101658

Please sign in to comment.