Skip to content

Commit

Permalink
update for trace
Browse files Browse the repository at this point in the history
  • Loading branch information
wadexu007 committed Nov 23, 2022
1 parent ade5b70 commit e20d069
Show file tree
Hide file tree
Showing 10 changed files with 322 additions and 78 deletions.
5 changes: 4 additions & 1 deletion Datadog/README.md
Expand Up @@ -53,4 +53,7 @@ terraform plan
terraform apply
```

<br>
### Datadog APM
Datadog Application Performance Monitoring [APM](./datadog_apm/)

<br>s
2 changes: 1 addition & 1 deletion Golang/demo_app_with_instrumentation/Makefile
@@ -1,4 +1,4 @@
export TAG=1.0.0
export TAG=1.1.2
export REPO=wadexu007/instrumented-app

hello:
Expand Down
25 changes: 22 additions & 3 deletions Golang/demo_app_with_instrumentation/controllers/book.go
Expand Up @@ -7,9 +7,22 @@ import (

"github.com/gin-gonic/gin"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/trace"
)

var meter = global.Meter("bookstore-meter")

var queryBooksCount, _ = meter.SyncInt64().Counter(
"bookstore/query_all_books_request_counts",
instrument.WithDescription("The number of query all books requests received"),
)
var queryBookCount, _ = meter.SyncInt64().Counter(
"bookstore/query_one_book_request_counts",
instrument.WithDescription("The number of query one book requests received"),
)

type CreateBookInput struct {
Title string `json:"title" binding:"required"`
Author string `json:"author" binding:"required"`
Expand All @@ -24,11 +37,16 @@ type UpdateBookInput struct {
// Find all books
func FindBooks(c *gin.Context) {
var books []models.Book
span := trace.SpanFromContext(c.Request.Context())

ctx := c.Request.Context()
span := trace.SpanFromContext(ctx)
span.SetAttributes(attribute.String("controller", "books"))
span.AddEvent("This is a sample event", trace.WithAttributes(attribute.Int("pid", 4328), attribute.String("sampleAttribute", "Test")))
models.DB.WithContext(c.Request.Context()).Find(&books)

models.DB.WithContext(ctx).Find(&books)
c.JSON(http.StatusOK, gin.H{"data": books})

queryBooksCount.Add(ctx, 1)
}

// GET /books/:id
Expand All @@ -40,8 +58,9 @@ func FindBook(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": "Record not found!"})
return
}

c.JSON(http.StatusOK, gin.H{"data": book})

queryBookCount.Add(c.Request.Context(), 1)
}

// POST /books
Expand Down
11 changes: 11 additions & 0 deletions Golang/demo_app_with_instrumentation/controllers/healthz.go
@@ -0,0 +1,11 @@
package controllers

import (
"net/http"

"github.com/gin-gonic/gin"
)

func Status(c *gin.Context) {
c.String(http.StatusOK, "pong!")
}
28 changes: 20 additions & 8 deletions Golang/demo_app_with_instrumentation/go.mod
Expand Up @@ -4,20 +4,27 @@ go 1.19

require (
github.com/gin-gonic/gin v1.8.1
github.com/prometheus/client_golang v1.14.0
github.com/uptrace/opentelemetry-go-extra/otelgorm v0.1.17
go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.36.4
go.opentelemetry.io/otel v1.11.1
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v0.33.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.11.1
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.11.1
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.11.1
go.opentelemetry.io/otel/exporters/prometheus v0.33.0
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v0.33.0
go.opentelemetry.io/otel/metric v0.33.0
go.opentelemetry.io/otel/sdk v1.11.1
go.opentelemetry.io/otel/sdk/metric v0.33.0
go.opentelemetry.io/otel/trace v1.11.1
google.golang.org/grpc v1.50.1
gorm.io/driver/sqlite v1.4.3
gorm.io/gorm v1.24.1
gorm.io/gorm v1.24.2
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
Expand All @@ -32,20 +39,25 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-sqlite3 v2.0.1+incompatible // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/mattn/go-sqlite3 v1.14.15 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/uptrace/opentelemetry-go-extra/otelsql v0.1.17 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.11.1 // indirect
go.opentelemetry.io/otel/metric v0.32.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.33.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1 // indirect
google.golang.org/grpc v1.50.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

0 comments on commit e20d069

Please sign in to comment.