Use CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1
Add the orbs
stanza below your version, invoking the orb:
1
2
orbs:
thundra-foresight: thundra-io/thundra-foresight@1.1.1
Use thundra-foresight
elements in your existing workflows and jobs.
Opt-in to use of uncertified orbs on your organization’s Security settings page.
Use Gradle command to integrate Thundra Foresight into your project and instrument your Gradle build. With this command, you can monitor your unit, integration, and end-to-end tests in your Gradle build with distributed tracing capabilities. Foresight is currently supporting JUnit and Selenium frameworks for Java runtime. However, making other frameworks such as TestNG available is in our roadmap. Python shell is required to successfully run this command at the moment.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
version: '2.1'
orbs:
thundra: thundra-io/thundra-foresight@1.0.0
jobs:
gradle:
docker:
- image: cimg/openjdk:11.0
steps:
- checkout
- thundra/gradle:
apikey: THUNDRA_APIKEY
project_id: THUNDRA_AGENT_TEST_PROJECT_ID
- run:
command: ./gradlew build --init-script $THUNDRA_GRADLE_INIT_SCRIPT_PATH
workflows:
example:
jobs:
- gradle
Use Maven command to integrate Thundra Foresight into your project and instrument your Maven build. With this command, you can monitor your unit, integration, and end-to-end tests in your Maven build with distributed tracing capabilities. Foresight is currently supporting JUnit and Selenium frameworks for Java runtime. However, making other frameworks such as TestNG available is in our roadmap. Python shell is required to successfully run this command at the moment.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
version: '2.1'
orbs:
thundra: thundra-io/thundra-foresight@1.0.0
jobs:
maven:
docker:
- image: cimg/openjdk:11.0
steps:
- checkout
- thundra/maven:
apikey: THUNDRA_APIKEY
project_id: THUNDRA_AGENT_TEST_PROJECT_ID
- run:
command: mvn clean verify
workflows:
example:
jobs:
- maven
Gradle Instrumentation
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
agent_version | Use a specific version of the Thundra Agent | No | '' | string |
apikey | Thundra's API Key | No | THUNDRA_APIKEY | env_var_name |
plugin_version | Use a specific version of the Gradle test plugin | No | '' | string |
project_id | Thundra's Test Project ID | No | THUNDRA_AGENT_TEST_PROJECT_ID | env_var_name |
Maven Instrumentation
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
agent_version | Use a specific version of the Thundra Agent | No | '' | string |
apikey | Thundra's API Key | No | THUNDRA_APIKEY | env_var_name |
instrumenter_version | Use a specific version of the Maven instrumentation script | No | '' | string |
parent_pom_path | Use if your parent pom is in somewhere other that ./pom.xml | No | '' | string |
project_id | Thundra's Test Project ID | No | THUNDRA_AGENT_TEST_PROJECT_ID | env_var_name |
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/orbs/licensing
version: 2.1
description: |
Thundra Foresight is a test monitoring tool that's powered by Thundra APM Agents that supports multiple runtimes, such as Java, NodeJS, and Python. This orb help you to monitor your unit, integration, and end-to-end tests with distributed tracing capabilities. It is currently supporting Java runtimes for your Maven and Gradle builds, for JUnit and Selenium frameworks. More runtime and test framework support are on the way to make it available for CircleCI users.
Python shell is also required to successfully run this orb at the moment.
display:
home_url: https://thundra.io
source_url: https://github.com/thundra-io/thundra-circleci-orb
commands:
gradle:
description: |
Gradle Instrumentation
parameters:
agent_version:
default: ""
description: Use a specific version of the Thundra Agent
type: string
apikey:
default: THUNDRA_APIKEY
description: Thundra's API Key
type: env_var_name
plugin_version:
default: ""
description: Use a specific version of the Gradle test plugin
type: string
project_id:
default: THUNDRA_AGENT_TEST_PROJECT_ID
description: Thundra's Test Project ID
type: env_var_name
steps:
- run:
command: |
echo "export THUNDRA_APIKEY=$<<parameters.apikey>>" >> $BASH_ENV
echo "export THUNDRA_AGENT_TEST_PROJECT_ID=$<<parameters.project_id>>" >> $BASH_ENV
echo "export THUNDRA_AGENT_VERSION=<<parameters.agent_version>>" >> $BASH_ENV
echo "export THUNDRA_GRADLE_TEST_PLUGIN_VERSION=<<parameters.plugin_version>>" >> $BASH_ENV
name: Export Thundra Environment Variables
- run:
command: |
import os
import urllib3
import shutil
import xml.etree.ElementTree as et
from distutils.version import StrictVersion
from typing import Optional
THUNDRA_AGENT_METADATA: str = 'https://repo.thundra.io/service/local/repositories/thundra-releases/content/io/thundra/agent/thundra-agent-bootstrap/maven-metadata.xml'
GRADLE_TEST_PLUGIN: str = 'https://repo1.maven.org/maven2/io/thundra/plugin/thundra-gradle-test-plugin/maven-metadata.xml'
def get_latest_version(repository: str, version: str = None) -> str:
http = urllib3.PoolManager()
response = http.request('GET', repository)
xml = et.fromstring(response.data)
available_versions = xml.findall('./versioning/versions/version')
available_versions_set = set(map(lambda x: x.text, available_versions))
latest_version = xml.find('./versioning/latest').text
if (version and (version in available_versions_set)):
return version
else:
return latest_version
def instrument(plugin_version: str = None, agent_version: str = None):
agent_path: str
http = urllib3.PoolManager()
gradle_plugin_version: Optional[str] = get_latest_version(
GRADLE_TEST_PLUGIN,
plugin_version,
)
if not gradle_plugin_version:
print("> Couldn't find an available version for Thundra Gradle Test Plugin")
print("> Instrumentation failed!")
return
thundra_agent_version: Optional[str] = get_latest_version(
THUNDRA_AGENT_METADATA,
agent_version,
)
if not thundra_agent_version:
print("> Couldn't find an available version for Thundra Agent")
print("> Instrumentation failed!")
return
thundra_agent_url = f'https://repo.thundra.io/service/local/repositories/thundra-releases/content/io/thundra/agent/thundra-agent-bootstrap/{thundra_agent_version}/thundra-agent-bootstrap-{thundra_agent_version}.jar'
if os.environ.get('LOCAL_AGENT_PATH'):
agent_path = os.environ.get('LOCAL_AGENT_PATH')
print(f'> Using the local agent at {agent_path}')
else:
print("> Downloading the agent...")
agent_path = '/tmp/thundra-agent-bootstrap.jar'
with open(agent_path, 'wb') as out:
r = http.request('GET', thundra_agent_url, preload_content=False)
shutil.copyfileobj(r, out)
print(f'> Successfully downloaded the agent to {agent_path}')
print("> Generating init file...")
init_file_path = "/tmp/thundra.gradle"
with open(init_file_path, 'w') as out:
init_file = f'''initscript {{
repositories {{
mavenCentral()
}}
dependencies {{
classpath "io.thundra.plugin:thundra-gradle-test-plugin:{gradle_plugin_version}"
}}
}}
allprojects {{
apply plugin: io.thundra.plugin.gradle.ThundraTestPlugin
repositories {{
mavenCentral()
}}
thundra {{
agentPath = "{agent_path}"
}}
}}
'''
out.write(init_file)
bash_env_file = os.environ.get("BASH_ENV")
with open(bash_env_file, "a") as bash_env:
bash_env.write(
f'export THUNDRA_GRADLE_INIT_SCRIPT_PATH={init_file_path}'
)
print(f'> Successfully generated init file at {init_file_path}')
api_key_env_name = os.environ.get("THUNDRA_APIKEY_ENV_NAME")
if not os.environ.get(api_key_env_name):
print('> Thundra API Key is not present. Exiting early...')
print('> Instrumentation failed.')
exit(0)
project_id_env_name = os.environ.get("THUNDRA_AGENT_TEST_PROJECT_ID_ENV_NAME")
if not os.environ.get(project_id_env_name):
print('> Thundra Project ID is not present. Exiting early...')
print('> Instrumentation failed.')
exit(0)
if os.environ.get('THUNDRA_AGENT_VERSION') and (StrictVersion(os.environ.get('THUNDRA_AGENT_VERSION') < StrictVersion("2.7.0"))):
print(f'Thundra Java Agent prior to 2.7.0 doesn\'t work with this action')
exit(0)
def run():
print(f'> [Thundra] Initializing the Thundra Action...')
print(f'> Instrumenting the application')
instrument(os.environ.get('THUNDRA_GRADLE_TEST_PLUGIN_VERSION'),
os.environ.get('THUNDRA_AGENT_VERSION'))
run()
environment:
THUNDRA_AGENT_TEST_PROJECT_ID_ENV_NAME: <<parameters.project_id>>
THUNDRA_AGENT_VERSION: <<parameters.agent_version>>
THUNDRA_APIKEY_ENV_NAME: <<parameters.apikey>>
THUNDRA_GRADLE_TEST_PLUGIN_VERSION: <<parameters.plugin_version>>
name: Run Thundra Gradle Instrumentation
shell: /usr/bin/python3
maven:
description: |
Maven Instrumentation
parameters:
agent_version:
default: ""
description: Use a specific version of the Thundra Agent
type: string
apikey:
default: THUNDRA_APIKEY
description: Thundra's API Key
type: env_var_name
instrumenter_version:
default: ""
description: Use a specific version of the Maven instrumentation script
type: string
parent_pom_path:
default: ""
description: Use if your parent pom is in somewhere other that ./pom.xml
type: string
project_id:
default: THUNDRA_AGENT_TEST_PROJECT_ID
description: Thundra's Test Project ID
type: env_var_name
steps:
- run:
command: |
echo "export THUNDRA_APIKEY=$<<parameters.apikey>>" >> $BASH_ENV
echo "export THUNDRA_AGENT_TEST_PROJECT_ID=$<<parameters.project_id>>" >> $BASH_ENV
echo "export THUNDRA_MAVEN_INSTRUMENTATION_PARENT_POM=<<parameters.parent_pom_path>>" >> $BASH_ENV
echo "export THUNDRA_AGENT_VERSION=<<parameters.agent_version>>" >> $BASH_ENV
echo "export THUNDRA_INSTRUMENTER_VERSION=<<parameters.instrumenter_version>>" >> $BASH_ENV
name: Export Thundra Environment Variables
- run:
command: |
import os
import urllib3
import shutil
import subprocess
import xml.etree.ElementTree as et
from distutils.version import StrictVersion
from typing import Optional
THUNDRA_AGENT_METADATA: str = 'https://repo.thundra.io/service/local/repositories/thundra-releases/content/io/thundra/agent/thundra-agent-bootstrap/maven-metadata.xml'
MAVEN_INSTRUMENTATION_METADATA: str = 'https://repo1.maven.org/maven2/io/thundra/plugin/thundra-agent-maven-test-instrumentation/maven-metadata.xml'
def get_latest_version(repository: str, version: str = None) -> str:
http = urllib3.PoolManager()
response = http.request('GET', repository)
xml = et.fromstring(response.data)
available_versions = xml.findall('./versioning/versions/version')
available_versions_set = set(map(lambda x: x.text, available_versions))
latest_version = xml.find('./versioning/latest').text
if (version and (version in available_versions_set)):
return version
else:
return latest_version
def instrument(instrumenter_version: str = None, agent_version: str = None):
agent_path: str
maven_instrumenter_path: str
http = urllib3.PoolManager()
maven_instrumenter_version: Optional[str] = get_latest_version(
MAVEN_INSTRUMENTATION_METADATA,
instrumenter_version,
)
if not maven_instrumenter_version:
print(
"> Couldn't find an available version for Thundra Maven Instrumentation script")
print("> Instrumentation failed!")
return
maven_instrumenter_url = f'https://repo1.maven.org/maven2/io/thundra/plugin/thundra-agent-maven-test-instrumentation/{maven_instrumenter_version}/thundra-agent-maven-test-instrumentation-{maven_instrumenter_version}.jar'
thundra_agent_version: Optional[str] = get_latest_version(
THUNDRA_AGENT_METADATA,
agent_version,
)
if not thundra_agent_version:
print("> Couldn't find an available version for Thundra Agent")
print("> Instrumentation failed!")
return
thundra_agent_url = f'https://repo.thundra.io/service/local/repositories/thundra-releases/content/io/thundra/agent/thundra-agent-bootstrap/{thundra_agent_version}/thundra-agent-bootstrap-{thundra_agent_version}.jar'
if os.environ.get('LOCAL_AGENT_PATH'):
agent_path = os.environ.get('LOCAL_AGENT_PATH')
print(f'> Using the local agent at {agent_path}')
else:
print("> Downloading the agent...")
agent_path = '/tmp/thundra-agent-bootstrap.jar'
with open(agent_path, 'wb') as out:
r = http.request('GET', thundra_agent_url, preload_content=False)
shutil.copyfileobj(r, out)
print(f'> Successfully downloaded the agent to {agent_path}')
print("> Downloading the maven instrumentater")
maven_instrumenter_path = f'/tmp/thundra-agent-maven-test-instrumentation-{maven_instrumenter_version}.jar'
with open(maven_instrumenter_path, 'wb') as out:
r = http.request('GET', maven_instrumenter_url, preload_content=False)
shutil.copyfileobj(r, out)
print(f'> Successfully downloaded the agent to {maven_instrumenter_path}')
print("> Updating pom.xml...")
poms = subprocess.run(
['sh', '-c', f'find . -name "pom.xml" -exec echo \'{{}}\' +'], capture_output=True)
if poms.stdout:
subprocess.call(['java', '-jar', maven_instrumenter_path,
agent_path, str(poms.stdout.strip(), 'utf-8')])
print("> Update to pom.xml is done")
else:
print("> Couldn't find any pom.xml files. Exiting the instrumentation step.")
api_key_env_name = os.environ.get("THUNDRA_APIKEY_ENV_NAME")
if not os.environ.get(api_key_env_name):
print('> Thundra API Key is not present. Exiting early...')
print('> Instrumentation failed.')
exit(0)
project_id_env_name = os.environ.get("THUNDRA_AGENT_TEST_PROJECT_ID_ENV_NAME")
if not os.environ.get(project_id_env_name):
print('> Thundra Project ID is not present. Exiting early...')
print('> Instrumentation failed.')
exit(0)
if os.environ.get('THUNDRA_AGENT_VERSION') and (StrictVersion(os.environ.get('THUNDRA_AGENT_VERSION') < StrictVersion("2.7.0"))):
print(f'Thundra Java Agent prior to 2.7.0 doesn\'t work with this action')
exit(0)
def run():
print(f'> [Thundra] Initializing the Thundra Action...')
print(f'> Instrumenting the application')
instrument(os.environ.get('THUNDRA_INSTRUMENTER_VERSION'),
os.environ.get('THUNDRA_AGENT_VERSION'))
run()
environment:
THUNDRA_AGENT_TEST_PROJECT_ID_ENV_NAME: <<parameters.project_id>>
THUNDRA_AGENT_VERSION: <<parameters.agent_version>>
THUNDRA_APIKEY_ENV_NAME: <<parameters.apikey>>
THUNDRA_INSTRUMENTER_VERSION: <<parameters.instrumenter_version>>
THUNDRA_MAVEN_INSTRUMENTATION_PARENT_POM: <<parameters.parent_pom_path>>
name: Run Thundra Maven Instrumentation
shell: /usr/bin/python3
examples:
use_gradle_command:
description: |
Use Gradle command to integrate Thundra Foresight into your project and instrument your Gradle build. With this command, you can monitor your unit, integration, and end-to-end tests in your Gradle build with distributed tracing capabilities. Foresight is currently supporting JUnit and Selenium frameworks for Java runtime. However, making other frameworks such as TestNG available is in our roadmap.
Python shell is required to successfully run this command at the moment.
usage:
version: "2.1"
orbs:
thundra: thundra-io/thundra-foresight@1.0.0
jobs:
gradle:
docker:
- image: cimg/openjdk:11.0
steps:
- checkout
- thundra/gradle:
apikey: THUNDRA_APIKEY
project_id: THUNDRA_AGENT_TEST_PROJECT_ID
- run:
command: ./gradlew build --init-script $THUNDRA_GRADLE_INIT_SCRIPT_PATH
workflows:
example:
jobs:
- gradle
use_maven_command:
description: |
Use Maven command to integrate Thundra Foresight into your project and instrument your Maven build. With this command, you can monitor your unit, integration, and end-to-end tests in your Maven build with distributed tracing capabilities. Foresight is currently supporting JUnit and Selenium frameworks for Java runtime. However, making other frameworks such as TestNG available is in our roadmap.
Python shell is required to successfully run this command at the moment.
usage:
version: "2.1"
orbs:
thundra: thundra-io/thundra-foresight@1.0.0
jobs:
maven:
docker:
- image: cimg/openjdk:11.0
steps:
- checkout
- thundra/maven:
apikey: THUNDRA_APIKEY
project_id: THUNDRA_AGENT_TEST_PROJECT_ID
- run:
command: mvn clean verify
workflows:
example:
jobs:
- maven