-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOTInstrumentation.class.st
136 lines (107 loc) · 3.47 KB
/
OTInstrumentation.class.st
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
"
Interface representing a single type instrumentation.
Part of an `OTInstrumentationModule`.
"
Class {
#name : 'OTInstrumentation',
#superclass : 'Object',
#classInstVars : [
'enabled',
'instrumenter',
'sampler'
],
#category : 'OpenTelemetry-Instrumentation',
#package : 'OpenTelemetry-Instrumentation'
}
{ #category : 'matching' }
OTInstrumentation class >> classMatcher [
"Matches all classes by default.
Subclasses should redefine this method to focus the search on interesting classes."
^ OTMatcher any
]
{ #category : 'configuring' }
OTInstrumentation class >> configure: installer [
"Redefine this method to configure the arguments given to the instrumentation method.
Use the instance-side API of a subclass of OTAgentInstaller."
]
{ #category : 'configuring' }
OTInstrumentation class >> defineInstrumenter [
"Redefine this method to define an OTInstrumenter to be used in the instrumentation methods.
It should be stored in the `instrumenter` class variable.
This is optional, but highly recommended if you want to generate spans.
Using an instrumenter has the advantage of handling boilerplate code for you, in particular the lifecycle and export of spans."
"instrumenter := OTInstrumenter new
instrumentationName: ...;
spanNameExtractor: [ :request | ... ];
spanKindExtractor: [ :request | ... ];
spanSuppressionStrategy: [ :span :kind | ... ];
contextProducer: [ ... ]"
]
{ #category : 'configuring' }
OTInstrumentation class >> defineSampler [
"Redefine this method to define an OTSampler to be used in the instrumentation methods.
It should be stored in the `sampler` class variable.
This is useful to limit the number of traces generated."
"sampler := OTSampler with..."
]
{ #category : 'accessing' }
OTInstrumentation class >> enabled [
"Instrumentations are enabled by default."
^ enabled ifNil: [ enabled := true ]
]
{ #category : 'accessing' }
OTInstrumentation class >> enabled: aBoolean [
enabled := aBoolean
]
{ #category : 'actions' }
OTInstrumentation class >> install [
"Install a specific subclass of Instrumentation."
<script>
self installer installInstrumentation: self
]
{ #category : 'configuring' }
OTInstrumentation class >> installer [
self subclassResponsibility
]
{ #category : 'testing' }
OTInstrumentation class >> isAbstract [
^ self == OTInstrumentation
]
{ #category : 'private' }
OTInstrumentation class >> matchingMethodsDo: aBlock [
| classMatcher methodMatcher |
classMatcher := self classMatcher.
methodMatcher := self methodMatcher.
self packageMatcher matchingPackagesDo: [ :package |
classMatcher matching: package classes do: [ :class |
methodMatcher
matching: class methods
do: [ :method | aBlock value: method ] ] ]
]
{ #category : 'matching' }
OTInstrumentation class >> methodMatcher [
"My subclasses must define a matcher for the methods to instrument."
self subclassResponsibility
]
{ #category : 'matching' }
OTInstrumentation class >> packageMatcher [
"Matches all packages by default.
Subclasses should redefine this method to focus the search on interesting packages."
^ OTMatcher any
]
{ #category : 'actions' }
OTInstrumentation class >> reinstall [
<script>
self uninstall.
self install
]
{ #category : 'class initialization' }
OTInstrumentation class >> reset [
instrumenter := sampler := nil
]
{ #category : 'actions' }
OTInstrumentation class >> uninstall [
"Uninstall a specific subclass of Instrumentation."
<script>
self installer resetEnvironment uninstallInstrumentation: self
]