-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOTAgentInstaller.class.st
153 lines (118 loc) · 4.05 KB
/
OTAgentInstaller.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"
I am a utility class in the OpenTelemetry framework designed to install and uninstall instrumentations using my class-side API.
I streamline the process of integrating instrumentation into existing codebases by providing an abstraction layer for managing instrumented methods.
I also handle permission management, allowing or denying the installation of instrumentations.
My instance-side API is used to configure the installation of instrumentations, allowing developers to fine-tune the behavior of instrumentations.
These methods allow them to specify contextual information, method parameters, receivers, and more that will be passed as arguments to the instrumentations.
This ensures that the instrumentation is tailored to the specific needs of the application.
"
Class {
#name : 'OTAgentInstaller',
#superclass : 'Object',
#classInstVars : [
'permission'
],
#category : 'OpenTelemetry-Instrumentation',
#package : 'OpenTelemetry-Instrumentation'
}
{ #category : 'class initialization' }
OTAgentInstaller class >> askPermission [
"command line and GUI"
self flag: #todo.
^ true
]
{ #category : 'class initialization' }
OTAgentInstaller class >> denyPermission [
<script>
permission := false.
self uninstall
]
{ #category : 'class initialization' }
OTAgentInstaller class >> givePermission [
<script>
permission := true.
self install
]
{ #category : 'class initialization' }
OTAgentInstaller class >> hasPermission [
^ permission ifNil: [ permission := self askPermission ]
]
{ #category : 'class initialization' }
OTAgentInstaller class >> initialize [
"Install the instrumentations when OpenTelemetry is loaded."
self hasPermission ifTrue: [ self install ]
]
{ #category : 'actions' }
OTAgentInstaller class >> install [
"Install all the active instrumentation modules present in this image."
<script>
OTInstrumentationModule subclasses do: [ :module |
module enabled ifTrue: [ self installModule: module ] ]
]
{ #category : 'actions' }
OTAgentInstaller class >> installInstrumentation: anInstrumentation [
"Install the instrumentation on all matching methods using the configured installer.
It is the receiver of this message, and should be one of my subclasses."
| installer |
installer := self new configureWith: anInstrumentation.
anInstrumentation
defineInstrumenter;
defineSampler;
matchingMethodsDo: [ :method |
(installer shouldInstrument: method with: anInstrumentation)
ifTrue: [ installer instrument: method ] ]
]
{ #category : 'actions' }
OTAgentInstaller class >> installModule: anInstrumentationModule [
"Install all enabled instrumentations from the module."
anInstrumentationModule initialize instrumentations do: [
:instrumentation |
instrumentation enabled ifTrue: [ instrumentation install ] ]
]
{ #category : 'testing' }
OTAgentInstaller class >> isAbstract [
^ self == OTAgentInstaller
]
{ #category : 'actions' }
OTAgentInstaller class >> reinstall [
<script>
self uninstall.
self install
]
{ #category : 'initialization' }
OTAgentInstaller class >> resetEnvironment [
<script>
OTSpan reset.
OTSpanProcessor flush
]
{ #category : 'actions' }
OTAgentInstaller class >> uninstall [
"Uninstall all of the instrumentation present in this image."
<script>
self resetEnvironment.
OTInstrumentationModule subclasses do: [ :module |
self uninstallModule: module ]
]
{ #category : 'actions' }
OTAgentInstaller class >> uninstallInstrumentation: anInstrumentation [
self subclassResponsibility
]
{ #category : 'actions' }
OTAgentInstaller class >> uninstallModule: anInstrumentationModule [
anInstrumentationModule instrumentations do: [ :instrumentation |
instrumentation uninstall ]
]
{ #category : 'private' }
OTAgentInstaller >> configureWith: anInstrumentation [
anInstrumentation configure: self
]
{ #category : 'private' }
OTAgentInstaller >> instrument: aMethod [
"This is a private method, do not use this!
Install the instrumentation on the method."
self subclassResponsibility
]
{ #category : 'private' }
OTAgentInstaller >> shouldInstrument: aMethod with: anInstrumentation [
self subclassResponsibility
]