-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Finish OpenTelemetry plugin * Fix CI
- Loading branch information
Showing
9 changed files
with
170 additions
and
4 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 |
---|---|---|
|
@@ -20,6 +20,7 @@ PLUGINS=\ | |
docs \ | ||
goakit \ | ||
i18n \ | ||
otel \ | ||
types \ | ||
zaplogger \ | ||
zerologger | ||
|
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
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,10 @@ | ||
#! /usr/bin/make | ||
# | ||
# Makefile for Goa otel plugin | ||
|
||
# include common Makefile content for plugins | ||
GOPATH=$(shell go env GOPATH) | ||
include ../plugins.mk | ||
|
||
# Make CI happy | ||
gen: |
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
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
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,50 @@ | ||
package otel | ||
|
||
import ( | ||
"bytes" | ||
"flag" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"goa.design/goa/v3/codegen" | ||
"goa.design/goa/v3/eval" | ||
httpcodegen "goa.design/goa/v3/http/codegen" | ||
"goa.design/plugins/v3/otel/testdata" | ||
) | ||
|
||
var update = flag.Bool("update", false, "update golden files") | ||
|
||
func TestOtel(t *testing.T) { | ||
cases := []struct { | ||
Name string | ||
DSL func() | ||
}{ | ||
{"one route", testdata.OneRoute}, | ||
{"multiple routes", testdata.MultipleRoutes}, | ||
} | ||
for _, c := range cases { | ||
t.Run(c.Name, func(t *testing.T) { | ||
root := codegen.RunDSL(t, c.DSL) | ||
serverFiles := httpcodegen.ServerFiles("gen", root) | ||
require.Len(t, serverFiles, 2) | ||
fs, err := Generate("", []eval.Root{root}, serverFiles) | ||
assert.NoError(t, err) | ||
require.Len(t, fs, 2) | ||
sections := fs[0].Section("server-handler") | ||
require.Len(t, sections, 1) | ||
section := sections[0] | ||
var buf bytes.Buffer | ||
assert.NoError(t, section.Write(&buf)) | ||
golden := filepath.Join("testdata", fmt.Sprintf("%s.golden", c.Name)) | ||
if *update { | ||
assert.NoError(t, os.WriteFile(golden, buf.Bytes(), 0644)) | ||
} | ||
expected, _ := os.ReadFile(golden) | ||
assert.Equal(t, buf.String(), string(expected)) | ||
}) | ||
} | ||
} |
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,28 @@ | ||
package testdata | ||
|
||
import ( | ||
. "goa.design/goa/v3/dsl" | ||
_ "goa.design/plugins/v3/docs" | ||
) | ||
|
||
var OneRoute = func() { | ||
Service("Service", func() { | ||
Method("Method", func() { | ||
HTTP(func() { | ||
GET("/") | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
var MultipleRoutes = func() { | ||
Service("Service2", func() { | ||
Method("Method", func() { | ||
HTTP(func() { | ||
GET("/") | ||
GET("/other") | ||
}) | ||
GRPC(func() {}) | ||
}) | ||
}) | ||
} |
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,12 @@ | ||
// MountMethodHandler configures the mux to serve the "Service2" service | ||
// "Method" endpoint. | ||
func MountMethodHandler(mux goahttp.Muxer, h http.Handler) { | ||
f, ok := h.(http.HandlerFunc) | ||
if !ok { | ||
f = func(w http.ResponseWriter, r *http.Request) { | ||
h.ServeHTTP(w, r) | ||
} | ||
} | ||
mux.Handle("GET", "/", otelhttp.WithRouteTag("/", f).ServeHTTP) | ||
mux.Handle("GET", "/other", otelhttp.WithRouteTag("/other", f).ServeHTTP) | ||
} |
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,11 @@ | ||
// MountMethodHandler configures the mux to serve the "Service" service | ||
// "Method" endpoint. | ||
func MountMethodHandler(mux goahttp.Muxer, h http.Handler) { | ||
f, ok := h.(http.HandlerFunc) | ||
if !ok { | ||
f = func(w http.ResponseWriter, r *http.Request) { | ||
h.ServeHTTP(w, r) | ||
} | ||
} | ||
mux.Handle("GET", "/", otelhttp.WithRouteTag("/", f).ServeHTTP) | ||
} |