Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support julienschmidt/httprouter #332

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
3 changes: 3 additions & 0 deletions _integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ toolchain go1.23.2

replace github.com/DataDog/orchestrion => ../

replace gopkg.in/DataDog/dd-trace-go.v1 => gopkg.in/DataDog/dd-trace-go.v1 v1.39.0-alpha.1.0.20241010143106-55426a1eca27

require (
cloud.google.com/go/pubsub v1.43.0
github.com/99designs/gqlgen v0.17.55
Expand Down Expand Up @@ -34,6 +36,7 @@ require (
github.com/graphql-go/handler v0.2.3
github.com/hashicorp/vault/api v1.15.0
github.com/jinzhu/gorm v1.9.16
github.com/julienschmidt/httprouter v1.3.0
github.com/labstack/echo/v4 v4.12.0
github.com/mattn/go-sqlite3 v1.14.22
github.com/redis/go-redis/v9 v9.6.1
Expand Down
6 changes: 4 additions & 2 deletions _integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,8 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
Expand Down Expand Up @@ -2412,8 +2414,8 @@ google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/DataDog/dd-trace-go.v1 v1.68.0 h1:8WPoOHJcMAtcxTVKM0DYnFweBjxxfNit3Sjo/rf+Hkw=
gopkg.in/DataDog/dd-trace-go.v1 v1.68.0/go.mod h1:mkZpWVLO/ERW5NqlW+w5d8waQKNvMSTUQLJfoI0vlvw=
gopkg.in/DataDog/dd-trace-go.v1 v1.39.0-alpha.1.0.20241010143106-55426a1eca27 h1:azCz/hkYCF9y5VmDU4EMne+6veESyn+Ot1fs/ljt3hg=
gopkg.in/DataDog/dd-trace-go.v1 v1.39.0-alpha.1.0.20241010143106-55426a1eca27/go.mod h1:U9AOeBHNAL95JXcd/SPf4a7O5GNeF/yD13sJtli/yaU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
19 changes: 19 additions & 0 deletions _integration-tests/tests/julienschmidt_httprouter/gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2023-present Datadog, Inc.

//go:build integration

package julienschmidt_httprouter

import (
"context"
"fmt"
"io"
"net/http"
"testing"
"time"

"github.com/julienschmidt/httprouter"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"orchestrion/integration/utils"
"orchestrion/integration/validator/trace"
)

type TestCase struct {
*http.Server
}

func (tc *TestCase) Setup(t *testing.T) {
router := httprouter.New()
router.GET("/ping", func(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, err := io.WriteString(w, `{"message": "pong"}`)
assert.NoError(t, err)
})
tc.Server = &http.Server{
rarguelloF marked this conversation as resolved.
Show resolved Hide resolved
Addr: "127.0.0.1:" + utils.GetFreePort(t),
Handler: router,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
}
go func() { assert.ErrorIs(t, tc.Server.ListenAndServe(), http.ErrServerClosed) }()
}

func (tc *TestCase) Run(t *testing.T) {
resp, err := http.Get(fmt.Sprintf("http://%s/ping", tc.Server.Addr))
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
}

func (tc *TestCase) Teardown(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
require.NoError(t, tc.Server.Shutdown(ctx))
}

func (tc *TestCase) ExpectedTraces() trace.Traces {
return trace.Traces{
{
Tags: map[string]any{
"name": "http.request",
"resource": "GET /ping",
"type": "http",
"service": "julienschmidt_httprouter.test",
},
Meta: map[string]string{
"component": "net/http",
"span.kind": "client",
},
Children: trace.Traces{
{
Tags: map[string]any{
"name": "http.request",
"resource": "GET /ping",
"type": "web",
"service": "julienschmidt_httprouter.test",
},
Meta: map[string]string{
"component": "net/http",
"span.kind": "server",
},
Children: trace.Traces{
{
Tags: map[string]any{
"name": "http.request",
"resource": "GET /ping",
"type": "web",
"service": "http.router",
},
Meta: map[string]string{
"component": "julienschmidt/httprouter",
"span.kind": "server",
},
},
},
},
},
},
}
}
48 changes: 42 additions & 6 deletions _integration-tests/tests/mux/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ type TestCase struct {
}

func (tc *TestCase) Setup(t *testing.T) {
mux := mux.NewRouter()
router := mux.NewRouter()
tc.Server = &http.Server{
Addr: "127.0.0.1:" + utils.GetFreePort(t),
Handler: mux,
Handler: router,
}

mux.HandleFunc("/ping", func(w http.ResponseWriter, _ *http.Request) {
router.HandleFunc("/ping", func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, err := io.WriteString(w, `{"message": "pong"}`)
Expand Down Expand Up @@ -66,19 +65,56 @@ func (tc *TestCase) ExpectedTraces() trace.Traces {
"name": "http.request",
"resource": "GET /ping",
"type": "http",
"service": "mux.test",
},
Meta: map[string]string{
"http.url": url,
"http.url": url,
"component": "net/http",
"span.kind": "client",
},
Children: trace.Traces{
{
Tags: map[string]any{
"name": "http.request",
"resource": "GET /ping",
"type": "web",
"service": "mux.test",
},
Meta: map[string]string{
"http.url": url,
"http.url": url,
"component": "net/http",
"span.kind": "server",
},
Children: trace.Traces{
{
Tags: map[string]any{
"name": "http.request",
"resource": "GET /ping",
"type": "web",
"service": "mux.router",
},
Meta: map[string]string{
"http.url": url,
"component": "gorilla/mux",
"span.kind": "server",
},
Children: trace.Traces{
{
// FIXME: this span shouldn't exist
Tags: map[string]any{
"name": "http.request",
"resource": "GET /ping",
"type": "web",
"service": "mux.router",
},
Meta: map[string]string{
"http.url": url,
"component": "net/http",
"span.kind": "server",
},
},
},
},
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ go 1.22.8

toolchain go1.23.2

replace gopkg.in/DataDog/dd-trace-go.v1 => gopkg.in/DataDog/dd-trace-go.v1 v1.39.0-alpha.1.0.20241010143106-55426a1eca27

require (
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/charmbracelet/lipgloss v0.13.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1330,8 +1330,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/DataDog/dd-trace-go.v1 v1.68.0 h1:8WPoOHJcMAtcxTVKM0DYnFweBjxxfNit3Sjo/rf+Hkw=
gopkg.in/DataDog/dd-trace-go.v1 v1.68.0/go.mod h1:mkZpWVLO/ERW5NqlW+w5d8waQKNvMSTUQLJfoI0vlvw=
gopkg.in/DataDog/dd-trace-go.v1 v1.39.0-alpha.1.0.20241010143106-55426a1eca27 h1:azCz/hkYCF9y5VmDU4EMne+6veESyn+Ot1fs/ljt3hg=
gopkg.in/DataDog/dd-trace-go.v1 v1.39.0-alpha.1.0.20241010143106-55426a1eca27/go.mod h1:U9AOeBHNAL95JXcd/SPf4a7O5GNeF/yD13sJtli/yaU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
30 changes: 29 additions & 1 deletion internal/injector/builtin/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/injector/builtin/generated_deps.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading