Skip to content

Commit d333b3a

Browse files
authored
Merge pull request #1 from aldas/first
first commit
2 parents 174f8ef + 871b6a9 commit d333b3a

14 files changed

Lines changed: 2011 additions & 0 deletions

File tree

.editorconfig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# EditorConfig coding styles definitions. For more information about the
2+
# properties used in this file, please see the EditorConfig documentation:
3+
# http://editorconfig.org/
4+
5+
# indicate this is the root of the project
6+
root = true
7+
8+
[*]
9+
charset = utf-8
10+
11+
end_of_line = LF
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
15+
indent_style = space
16+
indent_size = 2
17+
18+
[Makefile]
19+
indent_style = tab
20+
21+
[*.md]
22+
trim_trailing_whitespace = false
23+
24+
[*.go]
25+
indent_style = tab

.gitattributes

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Automatically normalize line endings for all text-based files
2+
# http://git-scm.com/docs/gitattributes#_end_of_line_conversion
3+
* text=auto
4+
5+
# For the following file types, normalize line endings to LF on checking and
6+
# prevent conversion to CRLF when they are checked out (this is required in
7+
# order to prevent newline related issues)
8+
.* text eol=lf
9+
*.go text eol=lf
10+
*.yml text eol=lf
11+
*.html text eol=lf
12+
*.md text eol=lf
13+
*.css text eol=lf
14+
*.js text eol=lf
15+
*.json text eol=lf
16+
LICENSE text eol=lf
17+

.github/workflows/checks.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Run checks
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read # to fetch code (actions/checkout)
14+
15+
env:
16+
# run static analysis only with the latest Go version
17+
LATEST_GO_VERSION: "1.26"
18+
19+
jobs:
20+
check:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout Code
24+
uses: actions/checkout@v5
25+
26+
- name: Set up Go ${{ matrix.go }}
27+
uses: actions/setup-go@v6
28+
with:
29+
go-version: ${{ env.LATEST_GO_VERSION }}
30+
check-latest: true
31+
32+
- name: Run golint
33+
run: |
34+
go install golang.org/x/lint/golint@latest
35+
golint -set_exit_status ./...
36+
37+
- name: Run staticcheck
38+
run: |
39+
go install honnef.co/go/tools/cmd/staticcheck@latest
40+
staticcheck ./...
41+
42+
- name: Run gosec
43+
run: |
44+
go install github.com/securego/gosec/v2/cmd/gosec@latest
45+
gosec -exclude-dir=.cache ./...
46+
47+
- name: Run govulncheck
48+
run: |
49+
go version
50+
go install golang.org/x/vuln/cmd/govulncheck@latest
51+
govulncheck ./...

.github/workflows/echo.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read # to fetch code (actions/checkout)
14+
15+
env:
16+
# run coverage and benchmarks only with the latest Go version
17+
LATEST_GO_VERSION: "1.26"
18+
19+
jobs:
20+
test:
21+
strategy:
22+
matrix:
23+
os: [ ubuntu-latest, macos-latest, windows-latest ]
24+
# Each major Go release is supported until there are two newer major releases. https://golang.org/doc/devel/release.html#policy
25+
# Echo tests with last four major releases (unless there are pressing vulnerabilities)
26+
# As we depend on `golang.org/x/` libraries which only support last 2 Go releases we could have situations when
27+
# we derive from last four major releases promise.
28+
go: [ "1.25", "1.26" ]
29+
name: ${{ matrix.os }} @ Go ${{ matrix.go }}
30+
runs-on: ${{ matrix.os }}
31+
steps:
32+
- name: Checkout Code
33+
uses: actions/checkout@v5
34+
35+
- name: Set up Go ${{ matrix.go }}
36+
uses: actions/setup-go@v6
37+
with:
38+
go-version: ${{ matrix.go }}
39+
40+
- name: Run Tests
41+
run: go test -race --coverprofile=coverage.coverprofile --covermode=atomic ./...
42+
43+
- name: Upload coverage to Codecov
44+
if: success() && matrix.go == env.LATEST_GO_VERSION && matrix.os == 'ubuntu-latest'
45+
uses: codecov/codecov-action@v5
46+
with:
47+
token:
48+
fail_ci_if_error: false
49+
50+
benchmark:
51+
needs: test
52+
name: Benchmark comparison
53+
runs-on: ubuntu-latest
54+
steps:
55+
- name: Checkout Code (Previous)
56+
uses: actions/checkout@v4
57+
with:
58+
ref: ${{ github.base_ref }}
59+
path: previous
60+
61+
- name: Checkout Code (New)
62+
uses: actions/checkout@v5
63+
with:
64+
path: new
65+
66+
- name: Set up Go ${{ matrix.go }}
67+
uses: actions/setup-go@v6
68+
with:
69+
go-version: ${{ env.LATEST_GO_VERSION }}
70+
71+
- name: Install Dependencies
72+
run: go install golang.org/x/perf/cmd/benchstat@latest
73+
74+
- name: Run Benchmark (Previous)
75+
run: |
76+
cd previous
77+
go test -run="-" -bench=".*" -count=8 ./... > benchmark.txt
78+
79+
- name: Run Benchmark (New)
80+
run: |
81+
cd new
82+
go test -run="-" -bench=".*" -count=8 ./... > benchmark.txt
83+
84+
- name: Run Benchstat
85+
run: |
86+
benchstat previous/benchmark.txt new/benchmark.txt

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
coverage.txt
3+
_test
4+
vendor
5+
.idea
6+
*.iml
7+
*.out
8+
.vscode

Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
PKG := "github.com/labstack/echo-opentelemetry"
2+
PKG_LIST := $(shell go list ${PKG}/...)
3+
4+
.DEFAULT_GOAL := check
5+
check: lint vet security race ## Check project
6+
7+
8+
init:
9+
@go install golang.org/x/lint/golint@latest
10+
@go install honnef.co/go/tools/cmd/staticcheck@latest
11+
@go install github.com/securego/gosec/v2/cmd/gosec@latest
12+
13+
lint: ## Lint the files
14+
@staticcheck ${PKG_LIST}
15+
@golint -set_exit_status ${PKG_LIST}
16+
17+
vet: ## Vet the files
18+
@go vet ${PKG_LIST}
19+
20+
security: ## Run Gosec static code security analyzer
21+
@gosec -quiet -exclude-dir=.cache ./...
22+
23+
test: ## Run tests
24+
@go test -short ${PKG_LIST}
25+
26+
race: ## Run tests with data race detector
27+
@go test -race ${PKG_LIST}
28+
29+
benchmark: ## Run benchmarks
30+
@go test -run="-" -bench=".*" ${PKG_LIST}
31+
32+
format: ## Format the source code
33+
@find ./ -type f -name "*.go" -exec gofmt -w {} \;
34+
35+
help: ## Display this help screen
36+
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
37+
38+
goversion ?= "1.26"
39+
test_version: ## Run tests inside Docker with given version (defaults to 1.26 oldest supported). Example: make test_version goversion=1.26
40+
@docker run --rm -it -v $(shell pwd):/project golang:$(goversion) /bin/sh -c "cd /project && make race"

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[![Sourcegraph](https://sourcegraph.com/github.com/labstack/echo-opentelemetry/-/badge.svg?style=flat-square)](https://sourcegraph.com/github.com/labstack/echo-opentelemetry?badge)
2+
[![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://pkg.go.dev/github.com/labstack/echo-opentelemetry)
3+
[![Go Report Card](https://goreportcard.com/badge/github.com/labstack/echo-opentelemetry?style=flat-square)](https://goreportcard.com/report/github.com/labstack/echo-opentelemetry)
4+
[![Codecov](https://img.shields.io/codecov/c/github/labstack/echo-opentelemetry.svg?style=flat-square)](https://codecov.io/gh/labstack/echo-opentelemetry)
5+
[![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://raw.githubusercontent.com/labstack/echo-opentelemetry/main/LICENSE)
6+
7+
# Echo OpenTelemetry (OTel) middleware
8+
9+
[OpenTelemetry](https://opentelemetry.io/) middleware for [Echo](https://github.com/labstack/echo) framework.
10+
11+
* [OpenTelemetry HTTP spec](https://opentelemetry.io/docs/specs/semconv/http/)
12+
* [HTTP metrics spec](https://opentelemetry.io/docs/specs/semconv/http/http-metrics/)
13+
14+
15+
## Versioning
16+
17+
* version `v0.x.y` tracks the latest Echo version (`v5`).
18+
* `main` branch is compatible with the latest Echo version (`v5`).
19+
20+
## Usage
21+
22+
Add OpenTelemetry middleware dependency with go modules
23+
24+
```bash
25+
go get github.com/labstack/echo-opentelemetry
26+
```
27+
28+
Use as import statement
29+
30+
```go
31+
import "github.com/labstack/echo-opentelemetry"
32+
```
33+
34+
Add middleware in simplified form, by providing only the server name
35+
36+
```go
37+
e.Use(echootel.NewMiddleware("app.example.com"))
38+
```
39+
40+
Add middleware with configuration options
41+
42+
```go
43+
e.Use(echootel.NewMiddlewareWithConfig(echootel.Config{
44+
ServerName: "my-server",
45+
TracerProvider: tp,
46+
}))
47+
```
48+
49+
50+
## Full example
51+
52+
TODO

0 commit comments

Comments
 (0)