Skip to content

Commit

Permalink
add tracing code
Browse files Browse the repository at this point in the history
  • Loading branch information
themarcelor committed Jun 3, 2024
1 parent 744275f commit beebe9d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 18 additions & 1 deletion emissor-de-metricas-simples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ import (
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"

sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
)

var meuContador otel_metric.Int64Counter

var tracer trace.Tracer

var (
outfile, _ = os.Create("minhaApp.log")
logger = log.New(outfile, "", 0)
Expand Down Expand Up @@ -95,6 +98,7 @@ func main() {
sdktrace.WithSpanProcessor(bsp),
)
otel.SetTracerProvider(tp)
tracer = otel.Tracer(serviceName)

mux := http.NewServeMux()
mux.Handle("/", otelhttp.NewHandler(otelhttp.WithRouteTag("/", http.HandlerFunc(HelloServer)), "root", otelhttp.WithPublicEndpoint()))
Expand All @@ -114,5 +118,18 @@ func HelloServer(w http.ResponseWriter, r *http.Request) {
logger.Print("emitindo metrica OTel...")
meuContador.Add(ctx, 1, opt)

fmt.Fprintf(w, "Olá, %s!", r.URL.Path[1:])
fmt.Fprintf(w, OtherFunction(ctx, r.URL.Path[1:]))
}

func OtherFunction(ctx context.Context, nome string) string {
_, span := tracer.Start(
ctx,
"digaOla",
trace.WithAttributes(attribute.String("AlgumAtributo", "QualquerValor")),
)
if span != nil {
defer span.End()
}

return fmt.Sprintf("Olá, %s!", nome)
}
3 changes: 3 additions & 0 deletions tempo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ storage:
backend: local
local:
path: /var/tempo/blocks

server:
http_listen_port: 9085

0 comments on commit beebe9d

Please sign in to comment.