You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2024/01/24 02:04:54 UTC
(skywalking-go) branch main updated: Add support ignore suffix (#163)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-go.git
The following commit(s) were added to refs/heads/main by this push:
new ffaa359 Add support ignore suffix (#163)
ffaa359 is described below
commit ffaa35950cf1bf1943d00c196042ec16d55ae24b
Author: Starry <co...@163.com>
AuthorDate: Wed Jan 24 10:04:49 2024 +0800
Add support ignore suffix (#163)
---
CHANGES.md | 1 +
docs/en/agent/tracing-metrics-logging.md | 7 ++++---
plugins/core/tracer.go | 5 ++++-
plugins/core/tracing.go | 25 +++++++++++++++++++----
tools/go-agent/config/agent.default.yaml | 2 ++
tools/go-agent/config/loader.go | 1 +
tools/go-agent/instrument/agentcore/instrument.go | 3 ++-
7 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index a6ef940..88dc93a 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -5,6 +5,7 @@ Release Notes.
0.4.0
------------------
#### Features
+* Add support ignore suffix.
#### Plugins
* Support setting a discard type of reporter.
diff --git a/docs/en/agent/tracing-metrics-logging.md b/docs/en/agent/tracing-metrics-logging.md
index 4d540eb..07ccf8d 100644
--- a/docs/en/agent/tracing-metrics-logging.md
+++ b/docs/en/agent/tracing-metrics-logging.md
@@ -22,9 +22,10 @@ If you wish to disable a particular plugin to prevent enhancements related to th
The basic configuration is as follows:
-| Name | Environment Key | Default Value | Description |
-|-------------------------|-------------------|-----------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
-| agent.sampler | SW_AGENT_SAMPLER | 1 | Sampling rate of tracing data, which is a floating-point value that must be between 0 and 1. |
+| Name | Environment Key | Default Value | Description |
+|---------------------|------------------------|--------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------|
+| agent.sampler | SW_AGENT_SAMPLER | 1 | Sampling rate of tracing data, which is a floating-point value that must be between 0 and 1. |
+| agent.ignore_suffix | SW_AGENT_IGNORE_SUFFIX | .jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.html,.svg | If the operation name of the first span is included in this set, this segment should be ignored.(multiple split by ","). |
## Metrics
diff --git a/plugins/core/tracer.go b/plugins/core/tracer.go
index a0b797c..e10a56b 100644
--- a/plugins/core/tracer.go
+++ b/plugins/core/tracer.go
@@ -22,6 +22,7 @@ import (
defLog "log"
"os"
"reflect"
+ "strings"
"sync"
"github.com/apache/skywalking-go/plugins/core/operator"
@@ -52,10 +53,11 @@ type Tracer struct {
// for all metrics
meterMap *sync.Map
meterCollectListeners []func()
+ ignoreSuffix []string
}
func (t *Tracer) Init(entity *reporter.Entity, rep reporter.Reporter, samp Sampler, logger operator.LogOperator,
- meterCollectSecond int, correlation *CorrelationConfig) error {
+ meterCollectSecond int, correlation *CorrelationConfig, ignoreSuffixStr string) error {
t.ServiceEntity = entity
t.Reporter = rep
t.Sampler = samp
@@ -66,6 +68,7 @@ func (t *Tracer) Init(entity *reporter.Entity, rep reporter.Reporter, samp Sampl
t.initFlag = 1
t.initMetricsCollect(meterCollectSecond)
t.correlation = correlation
+ t.ignoreSuffix = strings.Split(ignoreSuffixStr, ",")
// notify the tracer been init success
if len(GetInitNotify()) > 0 {
for _, fun := range GetInitNotify() {
diff --git a/plugins/core/tracing.go b/plugins/core/tracing.go
index fb7b132..8fac32f 100644
--- a/plugins/core/tracing.go
+++ b/plugins/core/tracing.go
@@ -20,6 +20,7 @@ package core
import (
"reflect"
"runtime/debug"
+ "strings"
"github.com/pkg/errors"
@@ -42,7 +43,7 @@ func (t *Tracer) DebugStack() []byte {
}
func (t *Tracer) CreateEntrySpan(operationName string, extractor interface{}, opts ...interface{}) (s interface{}, err error) {
- ctx, tracingSpan, noop := t.createNoop()
+ ctx, tracingSpan, noop := t.createNoop(operationName)
if noop {
return tracingSpan, nil
}
@@ -66,7 +67,7 @@ func (t *Tracer) CreateEntrySpan(operationName string, extractor interface{}, op
}
func (t *Tracer) CreateLocalSpan(operationName string, opts ...interface{}) (s interface{}, err error) {
- ctx, tracingSpan, noop := t.createNoop()
+ ctx, tracingSpan, noop := t.createNoop(operationName)
if noop {
return tracingSpan, nil
}
@@ -78,7 +79,7 @@ func (t *Tracer) CreateLocalSpan(operationName string, opts ...interface{}) (s i
}
func (t *Tracer) CreateExitSpan(operationName, peer string, injector interface{}, opts ...interface{}) (s interface{}, err error) {
- ctx, tracingSpan, noop := t.createNoop()
+ ctx, tracingSpan, noop := t.createNoop(operationName)
if noop {
return tracingSpan, nil
}
@@ -225,10 +226,13 @@ func (s *ContextSnapshot) IsValid() bool {
return s.activeSpan != nil && s.runtime != nil
}
-func (t *Tracer) createNoop() (*TracingContext, TracingSpan, bool) {
+func (t *Tracer) createNoop(operationName string) (*TracingContext, TracingSpan, bool) {
if !t.InitSuccess() || t.Reporter.ConnectionStatus() == reporter.ConnectionStatusDisconnect {
return nil, newNoopSpan(), true
}
+ if ignoreSuffixFilter(operationName, t.ignoreSuffix) {
+ return nil, newNoopSpan(), true
+ }
ctx := getTracingContext()
if ctx != nil {
span := ctx.ActiveSpan()
@@ -337,3 +341,16 @@ func saveSpanToActiveIfNotError(ctx *TracingContext, span interface{}, err error
ctx.SaveActiveSpan(span.(TracingSpan))
SetGLS(ctx)
}
+
+func ignoreSuffixFilter(operationName string, ignoreSuffix []string) bool {
+ suffixIdx := strings.LastIndex(operationName, ".")
+ if suffixIdx == -1 {
+ return false
+ }
+ for _, suffix := range ignoreSuffix {
+ if suffix == operationName[suffixIdx:] {
+ return true
+ }
+ }
+ return false
+}
diff --git a/tools/go-agent/config/agent.default.yaml b/tools/go-agent/config/agent.default.yaml
index 14835ee..0af4207 100644
--- a/tools/go-agent/config/agent.default.yaml
+++ b/tools/go-agent/config/agent.default.yaml
@@ -30,6 +30,8 @@ agent:
correlation:
max_key_count: ${SW_AGENT_CORRELATION_MAX_KEY_COUNT:3}
max_value_size: ${SW_AGENT_CORRELATION_MAX_VALUE_SIZE:128}
+ # If the operation name of the first span is included in this set, this segment should be ignored.(multiple split by ",")
+ ignore_suffix: ${SW_AGENT_IGNORE_SUFFIX:.jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.html,.svg}
reporter:
discard: ${SW_AGENT_REPORTER_DISCARD:false}
diff --git a/tools/go-agent/config/loader.go b/tools/go-agent/config/loader.go
index fa9c56b..e42420d 100644
--- a/tools/go-agent/config/loader.go
+++ b/tools/go-agent/config/loader.go
@@ -50,6 +50,7 @@ type Agent struct {
Sampler StringValue `yaml:"sampler"`
Meter Meter `yaml:"meter"`
Correlation Correlation `yaml:"correlation"`
+ IgnoreSuffix StringValue `yaml:"ignore_suffix"`
}
type Reporter struct {
diff --git a/tools/go-agent/instrument/agentcore/instrument.go b/tools/go-agent/instrument/agentcore/instrument.go
index 04af937..83dcbb6 100644
--- a/tools/go-agent/instrument/agentcore/instrument.go
+++ b/tools/go-agent/instrument/agentcore/instrument.go
@@ -162,7 +162,8 @@ func (t *Tracer) InitTracer(extend map[string]interface{}) {
MaxKeyCount : {{.Config.Agent.Correlation.MaxKeyCount.ToGoIntValue "loading the agent correlation maxKeyCount error"}},
MaxValueSize : {{.Config.Agent.Correlation.MaxValueSize.ToGoIntValue "loading the agent correlation maxValueSize error"}},
}
- if err := t.Init(entity, rep, samp, logger, meterCollectInterval, correlation); err != nil {
+ ignoreSuffixStr := {{.Config.Agent.IgnoreSuffix.ToGoStringValue}}
+ if err := t.Init(entity, rep, samp, logger, meterCollectInterval, correlation, ignoreSuffixStr); err != nil {
t.Log.Errorf("cannot initialize the SkyWalking Tracer: %v", err)
}
}`, struct {