Skip to content

Commit

Permalink
Instrumenter: calling #shouldStartUnder:request: is the responsibil…
Browse files Browse the repository at this point in the history
…ity of the instrumentation developer
  • Loading branch information
Gabriel-Darbord committed Dec 8, 2023
1 parent 0bfa43a commit 0a49ae1
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
Please describe the package using the class comment of the included manifest class. The manifest class also includes other additional metadata for the package. These meta data are used by other tools such as the SmalllintManifestChecker and the critics Browser
"
Class {
#name : #ManifestOpenTelemetryInstrumentation,
#superclass : #PackageManifest,
#category : #'OpenTelemetry-Instrumentation-Manifest'
#name : 'ManifestOpenTelemetryInstrumentation',
#superclass : 'PackageManifest',
#category : 'OpenTelemetry-Instrumentation-Manifest',
#package : 'OpenTelemetry-Instrumentation',
#tag : 'Manifest'
}

{ #category : #'code-critics' }
{ #category : 'code-critics' }
ManifestOpenTelemetryInstrumentation class >> ruleTempsReadBeforeWrittenRuleV1FalsePositive [

<ignoreForCoverage>
Expand Down
47 changes: 24 additions & 23 deletions src/OpenTelemetry-Instrumentation/OTAgentInstaller.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,57 @@ These methods allow them to specify contextual information, method parameters, r
This ensures that the instrumentation is tailored to the specific needs of the application.
"
Class {
#name : #OTAgentInstaller,
#superclass : #Object,
#name : 'OTAgentInstaller',
#superclass : 'Object',
#instVars : [
'metalink',
'arguments'
],
#classInstVars : [
'permission'
],
#category : #'OpenTelemetry-Instrumentation'
#category : 'OpenTelemetry-Instrumentation',
#package : 'OpenTelemetry-Instrumentation'
}

{ #category : #'class initialization' }
{ #category : 'class initialization' }
OTAgentInstaller class >> askPermission [
"command line and GUI"

self flag: #todo.
^ true
]

{ #category : #'class initialization' }
{ #category : 'class initialization' }
OTAgentInstaller class >> denyPermission [

<script>
permission := false.
self uninstall
]

{ #category : #'class initialization' }
{ #category : 'class initialization' }
OTAgentInstaller class >> givePermission [

<script>
permission := true.
self install
]

{ #category : #'class initialization' }
{ #category : 'class initialization' }
OTAgentInstaller class >> hasPermission [

^ permission ifNil: [ permission := self askPermission ]
]

{ #category : #'class initialization' }
{ #category : 'class initialization' }
OTAgentInstaller class >> initialize [
"Install the instrumentations when OpenTelemetry is loaded."

self hasPermission ifTrue: [ self install ]
]

{ #category : #actions }
{ #category : 'actions' }
OTAgentInstaller class >> install [
"Install all the active instrumentation modules present in this image."

Expand All @@ -66,7 +67,7 @@ OTAgentInstaller class >> install [
module enabled ifTrue: [ self installModule: module ] ]
]

{ #category : #actions }
{ #category : 'actions' }
OTAgentInstaller class >> installInstrumentation: anInstrumentation [

| installer |
Expand All @@ -80,7 +81,7 @@ OTAgentInstaller class >> installInstrumentation: anInstrumentation [
installer instrument: method ] ]
]

{ #category : #actions }
{ #category : 'actions' }
OTAgentInstaller class >> installModule: anInstrumentationModule [

anInstrumentationModule initialize instrumentations do: [
Expand All @@ -89,15 +90,15 @@ OTAgentInstaller class >> installModule: anInstrumentationModule [
self installInstrumentation: instrumentation ] ]
]

{ #category : #actions }
{ #category : 'actions' }
OTAgentInstaller class >> reinstall [

<script>
self uninstall.
self install
]

{ #category : #initialization }
{ #category : 'initialization' }
OTAgentInstaller class >> resetEnvironment [

<script>
Expand All @@ -106,7 +107,7 @@ OTAgentInstaller class >> resetEnvironment [
OTSpanExporter reset
]

{ #category : #actions }
{ #category : 'actions' }
OTAgentInstaller class >> uninstall [
"Uninstall all of the instrumentation present in this image."

Expand All @@ -116,7 +117,7 @@ OTAgentInstaller class >> uninstall [
self uninstallModule: module ]
]

{ #category : #actions }
{ #category : 'actions' }
OTAgentInstaller class >> uninstallInstrumentation: anInstrumentation [

anInstrumentation reset.
Expand All @@ -125,21 +126,21 @@ OTAgentInstaller class >> uninstallInstrumentation: anInstrumentation [
metalink uninstall ] ]
]

{ #category : #actions }
{ #category : 'actions' }
OTAgentInstaller class >> uninstallModule: anInstrumentationModule [

anInstrumentationModule instrumentations do: [ :instrumentation |
self uninstallInstrumentation: instrumentation ]
]

{ #category : #'API - configuration' }
{ #category : 'API - configuration' }
OTAgentInstaller >> beOneShot [
"Only execute the instrumentation once."

metalink optionOneShot: true
]

{ #category : #private }
{ #category : 'private' }
OTAgentInstaller >> configureWith: anInstrumentation [
"This is a private method, do not use this!
Configure the MetaLink to make it run the method instrumentation defined in an OTInstrumentation subclass."
Expand All @@ -151,7 +152,7 @@ OTAgentInstaller >> configureWith: anInstrumentation [
metalink metaObject: anInstrumentation
]

{ #category : #initialization }
{ #category : 'initialization' }
OTAgentInstaller >> initialize [

metalink := MetaLink new.
Expand All @@ -164,29 +165,29 @@ OTAgentInstaller >> initialize [
arguments add: #operation -> nil
]

{ #category : #private }
{ #category : 'private' }
OTAgentInstaller >> instrument: aMethod [
"This is a private method, do not use this!
Install the metalink on the instrumented method."

aMethod ast link: metalink
]

{ #category : #'API - configuration' }
{ #category : 'API - configuration' }
OTAgentInstaller >> withContext [
"The executing context, note that it is slow to reify."

arguments add: #context -> nil
]

{ #category : #'API - configuration' }
{ #category : 'API - configuration' }
OTAgentInstaller >> withObject [
"Object executing the instrumented method."

arguments add: #object -> nil
]

{ #category : #'API - configuration' }
{ #category : 'API - configuration' }
OTAgentInstaller >> withSender [
"Sender of the instrumented method."

Expand Down
13 changes: 7 additions & 6 deletions src/OpenTelemetry-Instrumentation/OTContext.class.st
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
Class {
#name : #OTContext,
#superclass : #Object,
#name : 'OTContext',
#superclass : 'Object',
#instVars : [
'currentSpan'
],
#category : 'OpenTelemetry-Instrumentation'
#category : 'OpenTelemetry-Instrumentation',
#package : 'OpenTelemetry-Instrumentation'
}

{ #category : #'accessing - context' }
{ #category : 'accessing - context' }
OTContext >> currentSpan [

^ currentSpan
]

{ #category : #accessing }
{ #category : 'accessing' }
OTContext >> currentSpan: aSpan [

currentSpan := aSpan
]

{ #category : #initialization }
{ #category : 'initialization' }
OTContext >> initialize [
"TODO gather data on executor"
]
39 changes: 20 additions & 19 deletions src/OpenTelemetry-Instrumentation/OTInstrumentation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,32 @@ Interface representing a single type instrumentation.
Part of an `OTelInstrumentationModule`.
"
Class {
#name : #OTInstrumentation,
#superclass : #Object,
#name : 'OTInstrumentation',
#superclass : 'Object',
#classInstVars : [
'enabled',
'instrumenter',
'sampler'
],
#category : #'OpenTelemetry-Instrumentation'
#category : 'OpenTelemetry-Instrumentation',
#package : 'OpenTelemetry-Instrumentation'
}

{ #category : #matching }
{ #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 }
{ #category : 'configuring' }
OTInstrumentation class >> configure: installer [
"Redefine this method to configure the arguments given to the instrumentation method.
Use the instance-side API of OTAgentInstaller."
]

{ #category : #configuring }
{ #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.
Expand All @@ -42,7 +43,7 @@ OTInstrumentation class >> defineInstrumenter [
contextProducer: [ ... ]"
]

{ #category : #configuring }
{ #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.
Expand All @@ -51,28 +52,28 @@ OTInstrumentation class >> defineSampler [
"sampler := OTSampler with..."
]

{ #category : #accessing }
{ #category : 'accessing' }
OTInstrumentation class >> enabled [
"Instrumentations are enabled by default."

^ enabled ifNil: [ enabled := true ]
]

{ #category : #accessing }
{ #category : 'accessing' }
OTInstrumentation class >> enabled: aBoolean [

enabled := aBoolean
]

{ #category : #actions }
{ #category : 'actions' }
OTInstrumentation class >> install [
"Install a specific subclass of Instrumentation."

<script>
OTAgentInstaller installInstrumentation: self
]

{ #category : #private }
{ #category : 'private' }
OTInstrumentation class >> matchingMethodsDo: aBlock [

| classMatcher methodMatcher |
Expand All @@ -85,49 +86,49 @@ OTInstrumentation class >> matchingMethodsDo: aBlock [
do: [ :method | aBlock value: method ] ] ]
]

{ #category : #matching }
{ #category : 'matching' }
OTInstrumentation class >> methodMatcher [
"My subclasses must define a matcher for the methods to instrument."

self subclassResponsibility
]

{ #category : #instrumenting }
{ #category : 'instrumenting' }
OTInstrumentation class >> onMethodEnter: event [
"This method is executed BEFORE the instrumented method.
The event contains the RFMethodOperation plus the data requested in #configure:."
]

{ #category : #instrumenting }
{ #category : 'instrumenting' }
OTInstrumentation class >> onMethodExit: event withValue: returnValue [
"This method is executed AFTER the instrumented method.
The first argument contains the RFMethodOperation plus the data requested in #configure:.
The second contains the return value of the method."
]

{ #category : #matching }
{ #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 }
{ #category : 'actions' }
OTInstrumentation class >> reinstall [

<script>
self uninstall.
self install
]

{ #category : #'class initialization' }
{ #category : 'class initialization' }
OTInstrumentation class >> reset [

instrumenter := sampler := nil
]

{ #category : #private }
{ #category : 'private' }
OTInstrumentation class >> run: arguments [
"Hook called when executing an instrumented method.
If the trace should not be sampled, execute the method directly.
Expand All @@ -148,7 +149,7 @@ OTInstrumentation class >> run: arguments [
self onMethodExit: arguments withValue: returnValue ]
]

{ #category : #actions }
{ #category : 'actions' }
OTInstrumentation class >> uninstall [
"Uninstall a specific subclass of Instrumentation."

Expand Down
Loading

0 comments on commit 0a49ae1

Please sign in to comment.