Skip to content

Commit

Permalink
More improvements and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alanwest committed Jun 14, 2024
1 parent dd19a25 commit 8506915
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
2 changes: 1 addition & 1 deletion getting-started-guides/go/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1

ARG GO_VERSION=1.20
ARG GO_VERSION=1.22
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS build
WORKDIR /src

Expand Down
2 changes: 1 addition & 1 deletion getting-started-guides/go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ It demonstrates how to configure OpenTelemetry Go to send data to New Relic.
in your web browser to ensure it is working.

```shell
go run *.go
go run .
```

3. Experiment with providing different values for `n` in the query string.
Expand Down
39 changes: 38 additions & 1 deletion getting-started-guides/go/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import (
"strconv"

"go.opentelemetry.io/otel/attribute"
<<<<<<< Updated upstream:getting-started-guides/go/app.go
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
=======
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/metric"
>>>>>>> Stashed changes:getting-started-guides/go/fibonacci.go
"go.opentelemetry.io/otel/trace"
)

Expand Down Expand Up @@ -101,6 +106,7 @@ func calculateFibonacci(
)
defer span.End()

<<<<<<< Updated upstream:getting-started-guides/go/app.go
fibonacciSpanAttrs := []attribute.KeyValue{
attribute.Int64("fibonacci.n", n),
}
Expand All @@ -123,16 +129,47 @@ func calculateFibonacci(
var n2, n1 int64 = 0, 1
for i := int64(2); i < n; i++ {
n2, n1 = n1, n1+n2
=======
span.SetAttributes(attribute.Int64("fibonacci.n", n))

if n < 1 || n > 90 {
err := errors.New("n must be between 1 and 90")
span.SetStatus(codes.Error, err.Error())
span.RecordError(err, trace.WithStackTrace(true))
fibonacciInvocations.Add(ctx, 1, metric.WithAttributes(attribute.Bool("fibonacci.valid.n", false)))
msg := fmt.Sprintf("Failed to compute fib(%d).", n)
logger.InfoContext(ctx, msg, "fibonacci.n", n)
return 0, err
}
res := n2 + n1

var result = int64(1)
if n > 2 {
var a = int64(0)
var b = int64(1)

for i := int64(1); i < n; i++ {
result = a + b
a = b
b = result
}
>>>>>>> Stashed changes:getting-started-guides/go/fibonacci.go
}

<<<<<<< Updated upstream:getting-started-guides/go/app.go
// Set calculation result into span
fibonacciSpanAttrs = append(fibonacciSpanAttrs,
attribute.Int64("fibonacci.result", res),
)
span.SetAttributes(fibonacciSpanAttrs...)

return res, nil
=======
span.SetAttributes(attribute.Int64("fibonacci.result", result))
fibonacciInvocations.Add(ctx, 1, metric.WithAttributes(attribute.Bool("fibonacci.valid.n", true)))
msg := fmt.Sprintf("Computed fib(%d) = %d.", n, result)
logger.InfoContext(ctx, msg, "fibonacci.n", n, "fibonacci.result", result)
return result, nil
>>>>>>> Stashed changes:getting-started-guides/go/fibonacci.go
}

func createHttpResponse(
Expand Down
29 changes: 29 additions & 0 deletions getting-started-guides/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,35 @@ module github.com/newrelic/newrelic-opentelemetry-examples/getting-started-guide
go 1.20

require (
<<<<<<< Updated upstream
go.opentelemetry.io/otel v1.21.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v0.44.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.21.0
go.opentelemetry.io/otel/metric v1.21.0
go.opentelemetry.io/otel/sdk v1.21.0
go.opentelemetry.io/otel/sdk/metric v1.21.0
go.opentelemetry.io/otel/trace v1.21.0
=======
go.opentelemetry.io/contrib/bridges/otelslog v0.2.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0
go.opentelemetry.io/contrib/instrumentation/runtime v0.52.0
go.opentelemetry.io/otel v1.27.0
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.3.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.27.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0
go.opentelemetry.io/otel/log v0.3.0
go.opentelemetry.io/otel/metric v1.27.0
go.opentelemetry.io/otel/sdk v1.27.0
go.opentelemetry.io/otel/sdk/log v0.3.0
go.opentelemetry.io/otel/sdk/metric v1.27.0
>>>>>>> Stashed changes
)

require (
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
<<<<<<< Updated upstream
github.com/golang/protobuf v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect
Expand All @@ -27,4 +43,17 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
=======
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 // indirect
go.opentelemetry.io/otel/trace v1.27.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
>>>>>>> Stashed changes
)

0 comments on commit 8506915

Please sign in to comment.