Introduction
To showcase the Opentelemetry functionality, we will be creating a basic Extension that serves up some HTTP endpoints using the Flask framework.
Specifically, the Extension will create three endpoints:
/upload
/files
/delete
The /upload
endpoint will accept payload using a POST request. The payload must be a JSON object with two fields: filename
and data
. Upon receiving valid payload, the Extension will create a file with name and contents specified by filename
and data
respectively.
The /files
endpoint will read the saved files and return them as a JSON array. The array will contain JSON objects with two fields: filename
and data
.
The /delete
endpoint will delete all the saved files.
Step 1 - Import the Extension Template
Go ahead and navigate to a directory where you would like to store the Extension. Download the attached Extension template below.
Open up the terminal to that folder and run
uip template add <path to OtelDemoTemplate.zip>
Reference
If you are unfamiliar with custom Extension templates, refer to Customizing Starter Templates.
You should now have the OtelDemo
Extension template imported. To verify, run
uip template list
and you should see the OtelDemo
template in the table.
OtelDemoTemplate.zip
is no longer needed; it can be deleted.
Step 2 - Initializing the OtelDemo
Extension
Now, we will create an Extension based off the OtelDemo
Extension template. Go ahead and run
uip init -t OtelDemo OtelDemoExt
This command should create a folder named OtelDemoExt
with the Extension inside of it.
Template Variables
The OtelDemo
Extension template has two customizable variables: host
and port
. For more information, run uip template list OtelDemo
Now would be a good time to go through src/
extension.py
and see how/what it's doing.
Step 3 - Testing the Extension
Go ahead and push the Extension to the Controller using
uip push -a
The requirements.txt
contains an entry for Flask
. It will be downloaded and packaged with the Extension automatically.
Once the Extension is in the Controller, create a task for it and run it. The Extension runs indefinitely until it's cancelled.
To interface with the web server, we will use the Web Service tasks that are built into the Controller, but other applications like Postman, Curl, etc. can also be used. Go ahead and create three Web Service tasks:
OtelDemoGetFiles
OtelDemoUploadFile
OtelDemoDeleteFiles
The host part of the URL will need to be changed according to how your Agent and Controller are set up.
Now, run the OtelDemoGetFiles
task, and it should succeed with the output being an empty array since we haven't uploaded any files yet. Next, run the OtelDemoUploadFile
task followed by the OtelDemoGetFiles
task. Both tasks should succeed, and the output of the OtelDemoGetFiles
task should be:
You can run the OtelDemoDeleteFiles
task now, which will delete test1.txt
.