Skip to content

Commit

Permalink
- 修复可能存在内存泄漏
Browse files Browse the repository at this point in the history
  • Loading branch information
dtapps committed Jun 17, 2024
1 parent 801a031 commit 6ba0628
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 57 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
#### 安装

```shell
go get -v -u go.dtapp.net/golog@v1.0.149
go get -v -u go.dtapp.net/golog@v1.0.150
```
6 changes: 3 additions & 3 deletions api_gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewApiGorm(ctx context.Context, gormClient *gorm.DB, gormTableName string)
func (ag *ApiGorm) Middleware(ctx context.Context, request gorequest.Response) {

// OpenTelemetry链路追踪
ctx, span := ag.TraceStartSpan(ctx)
ctx, span := TraceStartSpan(ctx, "api")

if ag.gormConfig.stats {
ag.gormMiddleware(ctx, span, request)
Expand All @@ -60,7 +60,7 @@ func (ag *ApiGorm) Middleware(ctx context.Context, request gorequest.Response) {
func (ag *ApiGorm) MiddlewareXml(ctx context.Context, request gorequest.Response) {

// OpenTelemetry链路追踪
ctx, span := ag.TraceStartSpan(ctx)
ctx, span := TraceStartSpan(ctx, "api.xml")

if ag.gormConfig.stats {
ag.gormMiddlewareXml(ctx, span, request)
Expand All @@ -73,7 +73,7 @@ func (ag *ApiGorm) MiddlewareXml(ctx context.Context, request gorequest.Response
func (ag *ApiGorm) MiddlewareCustom(ctx context.Context, api string, request gorequest.Response) {

// OpenTelemetry链路追踪
ctx, span := ag.TraceStartSpan(ctx)
ctx, span := TraceStartSpan(ctx, "api.custom")

if ag.gormConfig.stats {
ag.gormMiddlewareCustom(ctx, span, api, request)
Expand Down
13 changes: 0 additions & 13 deletions api_gorm.opentelemetry.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
package golog

import (
"context"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
)

// SetTrace 设置OpenTelemetry链路追踪
// TODO: 等待完全删除
func (ag *ApiGorm) SetTrace(trace bool) {
}

// TraceStartSpan 开始OpenTelemetry链路追踪状态
func (ag *ApiGorm) TraceStartSpan(ctx context.Context) (context.Context, trace.Span) {
tr := otel.Tracer("go.dtapp.net/golog", trace.WithInstrumentationVersion(Version))
ctx, span := tr.Start(ctx, "golog.api", trace.WithSpanKind(trace.SpanKindInternal))
return ctx, span
}
2 changes: 1 addition & 1 deletion gin_gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (gg *GinGorm) Middleware() gin.HandlerFunc {

// OpenTelemetry链路追踪
//g.Request = g.Request.WithContext(gg.TraceStartSpan(g))
ctx, span := gg.TraceStartSpan(g.Request.Context())
ctx, span := TraceStartSpan(g.Request.Context(), "gin")

// 开始时间
start := time.Now().UTC()
Expand Down
13 changes: 0 additions & 13 deletions gin_gorm.opentelemetry.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
package golog

import (
"context"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
)

// SetTrace 设置OpenTelemetry链路追踪
// TODO: 等待完全删除
func (gg *GinGorm) SetTrace(trace bool) {

}

// TraceStartSpan 开始OpenTelemetry链路追踪状态
func (gg *GinGorm) TraceStartSpan(ctx context.Context) (context.Context, trace.Span) {
tr := otel.Tracer("go.dtapp.net/golog", trace.WithInstrumentationVersion(Version))
ctx, span := tr.Start(ctx, "golog.gin", trace.WithSpanKind(trace.SpanKindInternal))
return ctx, span
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/gin-gonic/gin v1.10.0
github.com/hertz-contrib/requestid v1.1.0
go.dtapp.net/gojson v1.0.4
go.dtapp.net/gorequest v1.0.71
go.dtapp.net/gorequest v1.0.72
go.dtapp.net/gotime v1.0.11
go.dtapp.net/gourl v1.0.0
go.opentelemetry.io/otel v1.27.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ go.dtapp.net/gojson v1.0.4 h1:9en9iyOOLWoEIo2eKhqt3/Djh/3HhwsTpXxgI9efPRo=
go.dtapp.net/gojson v1.0.4/go.mod h1:G9CMVzNSRkbNzIic/vJqHCOyKtw6BW2YM8Vyn64zfM0=
go.dtapp.net/gorandom v1.0.3 h1:6RNDFMJfLlHFR98c2tbecaMzg4vEIHyEpduMBUdd0jc=
go.dtapp.net/gorandom v1.0.3/go.mod h1:Qd6ywCSrk7sCkh9OdR0wygcbQBFt53WDIrx8rqGBvis=
go.dtapp.net/gorequest v1.0.71 h1:x1AHjn/0iOjrtY4Myi9igxfE5yEQx0nUvtkWkaH4tPI=
go.dtapp.net/gorequest v1.0.71/go.mod h1:buYy18+d4jO3DbTl88BXyagilw5unU5FFDq5VfCehEg=
go.dtapp.net/gorequest v1.0.72 h1:vSZQdCyh9D3Ala3eKqU7NOTrrQBDNWmnmlh+buYURA0=
go.dtapp.net/gorequest v1.0.72/go.mod h1:buYy18+d4jO3DbTl88BXyagilw5unU5FFDq5VfCehEg=
go.dtapp.net/gostring v1.0.15 h1:MxvbgsBHSstIUdtwHf1FGtfh1bPbAlxxC+9NFVk396M=
go.dtapp.net/gostring v1.0.15/go.mod h1:AJLixiPhpBZrSKQ7yW46a+42iEIrOlfkJJ+Hta/j8RE=
go.dtapp.net/gotime v1.0.11 h1:VAmi1kFhkwJweIujeUOWf16wSmAZd4VyhyD25ku/J2Y=
Expand Down
2 changes: 1 addition & 1 deletion hertz_gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (hg *HertzGorm) Middleware() app.HandlerFunc {
return func(c context.Context, h *app.RequestContext) {

// OpenTelemetry链路追踪
ctx, span := hg.TraceStartSpan(c)
ctx, span := TraceStartSpan(c, "hertz")

// 开始时间
start := time.Now().UTC()
Expand Down
13 changes: 0 additions & 13 deletions hertz_gorm.opentelemetry.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
package golog

import (
"context"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
)

// SetTrace 设置OpenTelemetry链路追踪
// TODO: 等待完全删除
func (hg *HertzGorm) SetTrace(trace bool) {
}

// TraceStartSpan 开始OpenTelemetry链路追踪状态
func (hg *HertzGorm) TraceStartSpan(ctx context.Context) (context.Context, trace.Span) {
tr := otel.Tracer("go.dtapp.net/golog", trace.WithInstrumentationVersion(Version))
ctx, span := tr.Start(ctx, "golog.hertz", trace.WithSpanKind(trace.SpanKindInternal))
return ctx, span
}
12 changes: 12 additions & 0 deletions opentelemetry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package golog

import (
"context"
"go.dtapp.net/gorequest"
"go.opentelemetry.io/otel/trace"
)

// TraceStartSpan 开始OpenTelemetry链路追踪状态
func TraceStartSpan(ctx context.Context, spanName string) (context.Context, trace.Span) {
return gorequest.TraceNewSpan(ctx, "go.dtapp.net/golog", "golog.", spanName, Version, trace.SpanKindInternal)
}
2 changes: 1 addition & 1 deletion vendor/go.dtapp.net/gorequest/README.md

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

8 changes: 4 additions & 4 deletions vendor/go.dtapp.net/gorequest/http.go

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

2 changes: 1 addition & 1 deletion vendor/go.dtapp.net/gorequest/request_id.go

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

4 changes: 4 additions & 0 deletions vendor/go.dtapp.net/gorequest/trace_id.go

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

2 changes: 1 addition & 1 deletion vendor/go.dtapp.net/gorequest/version.go

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

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ go.dtapp.net/gojson/json
# go.dtapp.net/gorandom v1.0.3
## explicit; go 1.22
go.dtapp.net/gorandom
# go.dtapp.net/gorequest v1.0.71
# go.dtapp.net/gorequest v1.0.72
## explicit; go 1.22.3
go.dtapp.net/gorequest
# go.dtapp.net/gostring v1.0.15
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package golog

const (
Version = "1.0.149"
Version = "1.0.150"
)

0 comments on commit 6ba0628

Please sign in to comment.