Skip to content

Commit 2b5f9be

Browse files
authored
Merge branch 'apache:develop' into develop
2 parents 35cc9b9 + 29db209 commit 2b5f9be

File tree

6 files changed

+41
-20
lines changed

6 files changed

+41
-20
lines changed

.github/workflows/cloc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
echo "::set-output name=body::$(python3 -c "import json; j=json.load(open('cloc.json')); s=j.get('SUM',{}); print(f'Files: {s.get('files',0)}, Code: {s.get('code',0)}, Blank: {s.get('blank',0)}')")"
3737
3838
- name: post or update PR comment with cloc summary
39-
uses: peter-evans/create-or-update-comment@v3
39+
uses: peter-evans/create-or-update-comment@v3 # NOSONAR
4040
with:
4141
token: ${{ secrets.GITHUB_TOKEN }}
4242
issue-number: ${{ github.event.pull_request.number }}

.github/workflows/github-actions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
${{ runner.os }}-go-
6363
6464
- name: Check Code Format
65-
run: make fmt && git status && [[ -z `git status -s` ]]
65+
run: make check-fmt
6666

6767
- name: Unit Test
6868
run: make test

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ MAKEFLAGS += --no-print-directory
2626
CLI_DIR = tools/dubbogo-cli
2727
IMPORTS_FORMATTER_DIR = tools/imports-formatter
2828

29-
.PHONY: help test fmt clean lint
29+
.PHONY: help test fmt clean lint check-fmt
3030

3131
help:
3232
@echo "Available commands:"
@@ -46,6 +46,18 @@ fmt: install-imports-formatter
4646
go fmt ./... && GOROOT=$(shell go env GOROOT) imports-formatter
4747
cd $(CLI_DIR) && go fmt ./...
4848

49+
# This command is used in CI to verify that code formatting is correct
50+
check-fmt:
51+
@echo "Checking code format..."
52+
@$(MAKE) fmt
53+
@if ! git diff --exit-code --quiet; then \
54+
echo "Error: The following files have formatting changes:"; \
55+
git diff --name-only; \
56+
echo ""; \
57+
echo "Please run 'make fmt' to fix formatting issues and commit the changes."; \
58+
exit 1; \
59+
fi
60+
4961
# Clean test generate files
5062
clean:
5163
rm -rf coverage.txt

common/constant/otel.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717

1818
package constant
1919

20-
const (
21-
OtelPackageName = "go.opentelemetry.io/otel"
22-
)
20+
// TraceScopeName is unique name of trace used for the filter
21+
// Reference: https://github.com/open-telemetry/opentelemetry-specification/
22+
const TraceScopeName = "dubbo.apache.org/dubbo-go/v3/filter/otel/trace"

filter/otel/trace/attachment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type metadataSupplier struct {
3333
metadata map[string]any
3434
}
3535

36-
var _ propagation.TextMapCarrier = &metadataSupplier{}
36+
var _ propagation.TextMapCarrier = (*metadataSupplier)(nil)
3737

3838
func (s *metadataSupplier) Get(key string) string {
3939
if s.metadata == nil {

filter/otel/trace/filter.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"go.opentelemetry.io/otel/baggage"
2727
"go.opentelemetry.io/otel/codes"
2828
"go.opentelemetry.io/otel/propagation"
29-
"go.opentelemetry.io/otel/sdk"
3029
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
3130
"go.opentelemetry.io/otel/trace"
3231
)
@@ -55,6 +54,11 @@ func init() {
5554
})
5655
}
5756

57+
var _ filter.Filter = (*otelServerFilter)(nil)
58+
59+
// otelServerFilter implements server-side tracing for Dubbo requests
60+
// by creating and managing trace spans using the configured propagator
61+
// and tracer provider.
5862
type otelServerFilter struct {
5963
Propagators propagation.TextMapPropagator
6064
TracerProvider trace.TracerProvider
@@ -70,8 +74,8 @@ func (f *otelServerFilter) Invoke(ctx context.Context, invoker base.Invoker, inv
7074
ctx = baggage.ContextWithBaggage(ctx, bags)
7175

7276
tracer := f.TracerProvider.Tracer(
73-
constant.OtelPackageName,
74-
trace.WithInstrumentationVersion(sdk.Version()),
77+
constant.TraceScopeName,
78+
trace.WithInstrumentationVersion(constant.Version),
7579
)
7680

7781
ctx, span := tracer.Start(
@@ -86,16 +90,21 @@ func (f *otelServerFilter) Invoke(ctx context.Context, invoker base.Invoker, inv
8690
)
8791
defer span.End()
8892

89-
result := invoker.Invoke(ctx, invocation)
93+
res := invoker.Invoke(ctx, invocation)
9094

91-
if result.Error() != nil {
92-
span.SetStatus(codes.Error, result.Error().Error())
95+
if res.Error() != nil {
96+
span.SetStatus(codes.Error, res.Error().Error())
9397
} else {
9498
span.SetStatus(codes.Ok, codes.Ok.String())
9599
}
96-
return result
100+
return res
97101
}
98102

103+
var _ filter.Filter = (*otelClientFilter)(nil)
104+
105+
// otelClientFilter implements client-side tracing for Dubbo requests
106+
// by creating and managing trace spans using the configured propagator
107+
// and tracer provider.
99108
type otelClientFilter struct {
100109
Propagators propagation.TextMapPropagator
101110
TracerProvider trace.TracerProvider
@@ -107,8 +116,8 @@ func (f *otelClientFilter) OnResponse(ctx context.Context, result result.Result,
107116

108117
func (f *otelClientFilter) Invoke(ctx context.Context, invoker base.Invoker, invocation base.Invocation) result.Result {
109118
tracer := f.TracerProvider.Tracer(
110-
constant.OtelPackageName,
111-
trace.WithInstrumentationVersion(sdk.Version()),
119+
constant.TraceScopeName,
120+
trace.WithInstrumentationVersion(constant.Version),
112121
)
113122

114123
var span trace.Span
@@ -132,12 +141,12 @@ func (f *otelClientFilter) Invoke(ctx context.Context, invoker base.Invoker, inv
132141
for k, v := range attachments {
133142
invocation.SetAttachment(k, v)
134143
}
135-
result := invoker.Invoke(ctx, invocation)
144+
res := invoker.Invoke(ctx, invocation)
136145

137-
if result.Error() != nil {
138-
span.SetStatus(codes.Error, result.Error().Error())
146+
if res.Error() != nil {
147+
span.SetStatus(codes.Error, res.Error().Error())
139148
} else {
140149
span.SetStatus(codes.Ok, codes.Ok.String())
141150
}
142-
return result
151+
return res
143152
}

0 commit comments

Comments
 (0)