-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
release(otel): Bump otel package to v0.1.0
- Loading branch information
1 parent
4e4f2ae
commit c101658
Showing
3 changed files
with
38 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"))) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters