Feat : Update PR as comment
This commit is contained in:
@@ -57,8 +57,8 @@ const (
|
||||
// ContextKeyParentID is the context key for storing and retrieving the parent ID from a request context
|
||||
ContextKeyParentID ContextKey = "parent_id"
|
||||
|
||||
// ContextKeyCallerID is the context key for the caller who is calling the bap/bpp
|
||||
ContextKeyCallerID ContextKey = "caller_id"
|
||||
// ContextKeyRemoteID is the context key for the caller who is calling the bap/bpp
|
||||
ContextKeyRemoteID ContextKey = "caller_id"
|
||||
)
|
||||
|
||||
var contextKeys = map[string]ContextKey{
|
||||
@@ -67,7 +67,7 @@ var contextKeys = map[string]ContextKey{
|
||||
"subscriber_id": ContextKeySubscriberID,
|
||||
"module_id": ContextKeyModuleID,
|
||||
"parent_id": ContextKeyParentID,
|
||||
"caller_id": ContextKeyCallerID,
|
||||
"caller_id": ContextKeyRemoteID,
|
||||
}
|
||||
|
||||
// ParseContextKey converts a string into a valid ContextKey.
|
||||
|
||||
@@ -41,9 +41,18 @@ func (m metricsProvider) New(ctx context.Context, config map[string]string) (*te
|
||||
if v := ctx.Value(model.ContextKeyParentID); v != nil {
|
||||
parentID := v.(string)
|
||||
p := strings.Split(parentID, ":")
|
||||
deviceId = p[len(p)-1]
|
||||
producerType = p[0]
|
||||
producer = p[1]
|
||||
if len(p) >= 3 {
|
||||
producerType = p[0]
|
||||
producer = p[1]
|
||||
deviceId = p[len(p)-1]
|
||||
} else if len(p) >= 2 {
|
||||
producerType = p[0]
|
||||
producer = p[1]
|
||||
deviceId = p[1]
|
||||
} else if len(p) >= 1 {
|
||||
producerType = p[0]
|
||||
deviceId = p[0]
|
||||
}
|
||||
}
|
||||
|
||||
if deviceId != "" {
|
||||
@@ -97,7 +106,7 @@ func (m metricsProvider) New(ctx context.Context, config map[string]string) (*te
|
||||
}
|
||||
}
|
||||
|
||||
//to set network leval matric frequency and granularity
|
||||
//to set network level matric frequency and granularity
|
||||
if v, ok := config["networkMetricsGranularity"]; ok && v != "" {
|
||||
telemetry.SetNetworkMetricsConfig(v, "")
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ func (Setup) New(ctx context.Context, cfg *Config) (*telemetry.Provider, error)
|
||||
}, nil
|
||||
}
|
||||
|
||||
//this will be used by both matric and traces
|
||||
//this will be used by both metric and traces
|
||||
|
||||
// to build resource with envelope metadata
|
||||
baseAttrs := []attribute.KeyValue{
|
||||
@@ -123,10 +123,10 @@ func (Setup) New(ctx context.Context, cfg *Config) (*telemetry.Provider, error)
|
||||
|
||||
resMetric, err := resource.New(ctx, resource.WithAttributes(buildAtts(baseAttrs, "METRIC")...))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create telemetry resource for matric: %w", err)
|
||||
return nil, fmt.Errorf("failed to create telemetry resource for metric: %w", err)
|
||||
}
|
||||
|
||||
//OTLP matric
|
||||
//OTLP metric
|
||||
var meterProvider *metric.MeterProvider
|
||||
if cfg.EnableMetrics {
|
||||
metricExpoter, err := otlpmetricgrpc.New(ctx, otlpmetricgrpc.WithEndpoint(cfg.OtlpEndpoint),
|
||||
@@ -139,7 +139,7 @@ func (Setup) New(ctx context.Context, cfg *Config) (*telemetry.Provider, error)
|
||||
otel.SetMeterProvider(meterProvider)
|
||||
log.Infof(ctx, "OpenTelemetry metrics initialized for service=%s version=%s env=%s (OTLP endpoint=%s)",
|
||||
cfg.ServiceName, cfg.ServiceVersion, cfg.Environment, cfg.OtlpEndpoint)
|
||||
// for the go runtime matrics
|
||||
// for the go runtime metrics
|
||||
if err := runtime.Start(runtime.WithMinimumReadMemStatsInterval(runtime.DefaultMinimumReadMemStatsInterval)); err != nil {
|
||||
log.Warnf(ctx, "Failed to start Go runtime instrumentation: %v", err)
|
||||
}
|
||||
|
||||
@@ -75,8 +75,8 @@ func NewPreProcessor(cfg *Config) (func(http.Handler) http.Handler, error) {
|
||||
}
|
||||
|
||||
if callerID != nil {
|
||||
log.Debugf(ctx, "adding callerID to request:%s, %v", model.ContextKeyCallerID, callerID)
|
||||
ctx = context.WithValue(ctx, model.ContextKeyCallerID, callerID)
|
||||
log.Debugf(ctx, "adding callerID to request:%s, %v", model.ContextKeyRemoteID, callerID)
|
||||
ctx = context.WithValue(ctx, model.ContextKeyRemoteID, callerID)
|
||||
}
|
||||
for _, key := range cfg.ContextKeys {
|
||||
ctxKey, _ := model.ParseContextKey(key)
|
||||
|
||||
@@ -108,41 +108,6 @@ func getFieldForAction(ctx context.Context, action string) []string {
|
||||
return auditRules["default"]
|
||||
}
|
||||
|
||||
//func getByPath(root map[string]interface{}, path string) (interface{}, bool) {
|
||||
//
|
||||
// parts := strings.Split(path, ".")
|
||||
// var cur interface{} = root
|
||||
//
|
||||
// for _, part := range parts {
|
||||
// m, ok := cur.(map[string]interface{})
|
||||
// if !ok {
|
||||
// return nil, false
|
||||
// }
|
||||
// v, ok := m[part]
|
||||
// if !ok {
|
||||
// return nil, false
|
||||
// }
|
||||
// cur = v
|
||||
// }
|
||||
// return cur, true
|
||||
//}
|
||||
//
|
||||
//func setByPath(root map[string]interface{}, path string, value interface{}) {
|
||||
// parts := strings.Split(path, ".")
|
||||
// cur := root
|
||||
//
|
||||
// for i := 0; i < len(parts)-1; i++ {
|
||||
// k := parts[i]
|
||||
// next, ok := cur[k].(map[string]interface{})
|
||||
// if !ok {
|
||||
// next = map[string]interface{}{}
|
||||
// cur[k] = next
|
||||
// }
|
||||
// cur = next
|
||||
// }
|
||||
// cur[parts[len(parts)-1]] = value
|
||||
//}
|
||||
|
||||
func projectPath(cur interface{}, parts []string) (interface{}, bool) {
|
||||
if len(parts) == 0 {
|
||||
return cur, true
|
||||
|
||||
@@ -50,7 +50,7 @@ var (
|
||||
AttrMetricGranularity = attribute.Key("metric.granularity")
|
||||
AttrMetricFrequency = attribute.Key("metric.frequency")
|
||||
AttrObservedTimeUnixNano = attribute.Key("observedTimeUnixNano")
|
||||
AttrMatricLabels = attribute.Key("metric.labels")
|
||||
AttrMetricLabels = attribute.Key("metric.labels")
|
||||
AttrSenderID = attribute.Key("sender.id")
|
||||
AttrRecipientID = attribute.Key("recipient.id")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user