-
Notifications
You must be signed in to change notification settings - Fork 416
/
op_messaging.go
90 lines (76 loc) · 2.79 KB
/
op_messaging.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2023 Datadog, Inc.
package namingschema
import "fmt"
type messagingOutboundOp struct {
cfg *config
system string
}
// NewMessagingOutboundOp creates a new naming schema for outbound operations from messaging systems.
func NewMessagingOutboundOp(system string, opts ...Option) *Schema {
cfg := &config{}
for _, opt := range opts {
opt(cfg)
}
return New(&messagingOutboundOp{cfg: cfg, system: system})
}
func (m *messagingOutboundOp) V0() string {
if v, ok := m.cfg.versionOverrides[SchemaV0]; ok {
return v
}
return m.V1()
}
func (m *messagingOutboundOp) V1() string {
if v, ok := m.cfg.versionOverrides[SchemaV1]; ok {
return v
}
return fmt.Sprintf("%s.send", m.system)
}
type messagingInboundOp struct {
cfg *config
system string
}
// NewMessagingInboundOp creates a new schema for messaging systems inbound operations.
// The V0 implementation defaults to the v1 and is meant to be overwritten if needed, since (generally) it does not
// follow any pattern among messaging integrations.
func NewMessagingInboundOp(system string, opts ...Option) *Schema {
cfg := &config{}
for _, opt := range opts {
opt(cfg)
}
return New(&messagingInboundOp{cfg: cfg, system: system})
}
func (m *messagingInboundOp) V0() string {
if v, ok := m.cfg.versionOverrides[SchemaV0]; ok {
return v
}
return m.V1()
}
func (m *messagingInboundOp) V1() string {
if v, ok := m.cfg.versionOverrides[SchemaV1]; ok {
return v
}
return fmt.Sprintf("%s.process", m.system)
}
// NewKafkaOutboundOp creates a new schema for Kafka (messaging) outbound operations.
func NewKafkaOutboundOp(opts ...Option) *Schema {
newOpts := append([]Option{WithVersionOverride(SchemaV0, "kafka.produce")}, opts...)
return NewMessagingOutboundOp("kafka", newOpts...)
}
// NewKafkaInboundOp creates a new schema for Kafka (messaging) inbound operations.
func NewKafkaInboundOp(opts ...Option) *Schema {
newOpts := append([]Option{WithVersionOverride(SchemaV0, "kafka.consume")}, opts...)
return NewMessagingInboundOp("kafka", newOpts...)
}
// NewGCPPubsubInboundOp creates a new schema for GCP Pubsub (messaging) inbound operations.
func NewGCPPubsubInboundOp(opts ...Option) *Schema {
newOpts := append([]Option{WithVersionOverride(SchemaV0, "pubsub.receive")}, opts...)
return NewMessagingInboundOp("gcp.pubsub", newOpts...)
}
// NewGCPPubsubOutboundOp creates a new schema for GCP Pubsub (messaging) outbound operations.
func NewGCPPubsubOutboundOp(opts ...Option) *Schema {
newOpts := append([]Option{WithVersionOverride(SchemaV0, "pubsub.publish")}, opts...)
return NewMessagingOutboundOp("gcp.pubsub", newOpts...)
}