Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Build otelinit
run: go build -v ./...
- name: Build test stub
working-directory: ./cmd/test-otel-init-go
run: go build -v
- name: Install otel-cli for tests
uses: engineerd/[email protected]
with:
name: "otel-cli"
pathInArchive: /otel-cli
url: "https://github.com/equinix-labs/otel-cli/releases/download/v0.0.5/otel-cli-0.0.5-Linux-x86_64.tar.gz"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it require a GITHUB_TOKEN secret? I think I tried that first and it wanted me to set up more stuff and the way these repos are configured I didn't feel it was worth the trouble.

In any case I'll probably refactor this out soon.

- name: Test
run: go test -v ./...
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
cmd/test-otel-init-go/test-otel-init-go
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

func main() {
ctx := context.Background()
otelShutdown := otelinit.InitOpenTelemetry(ctx, "my-amazing-application")
ctx, otelShutdown := otelinit.InitOpenTelemetry(ctx, "my-amazing-application")
defer otelShutdown(ctx)
}
```
Expand Down
73 changes: 73 additions & 0 deletions cmd/test-otel-init-go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package main

// All this program does is load up otel-init-go, create one trace, dump state
// in json for all these things, then exit. This data is intended to be consumed
// in main_test.go, which is really about testing otel-cli-init itself.

import (
"context"
"encoding/json"
"log"
"os"
"strconv"
"strings"

"github.com/equinix-labs/otel-init-go/otelinit"
"go.opentelemetry.io/otel"
)

func main() {
ctx := context.Background()
ctx, otelShutdown := otelinit.InitOpenTelemetry(ctx, "otel-init-go-test")
defer otelShutdown(ctx)

tracer := otel.Tracer("otel-init-go-test")
ctx, span := tracer.Start(ctx, "dump state")

env := make(map[string]string)
for _, e := range os.Environ() {
parts := strings.SplitN(e, "=", 2)
if len(parts) == 2 {
// it's not great to hard-code a specific envvar here but this is
// probably the most dangerous one we don't want to blithely print
// here. open to suggestions...
if !strings.HasPrefix(parts[0], "GITHUB") {
env[parts[0]] = parts[1]
}
} else {
log.Fatalf("BUG this shouldn't happen")
}
}

// public.go stuffs the config in the context just so we can do this
conf, ok := otelinit.ConfigFromContext(ctx)
if !ok {
log.Println("failed to retrieve otelinit.Config pointer from context, test results may be invalid")
conf = &otelinit.Config{}
}
sc := span.SpanContext()
outData := map[string]map[string]string{
"config": {
"endpoint": conf.Endpoint,
"service_name": conf.Servicename,
"insecure": strconv.FormatBool(conf.Insecure),
},
"otel": {
"trace_id": sc.TraceID().String(),
"span_id": sc.SpanID().String(),
"trace_flags": sc.TraceFlags().String(),
"is_sampled": strconv.FormatBool(sc.IsSampled()),
},
"env": env,
}

js, err := json.MarshalIndent(outData, "", " ")
if err != nil {
log.Fatal(err)
}

os.Stdout.Write(js)
os.Stdout.WriteString("\n")

span.End()
}
Loading