Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Panel

Table of Contents
maxLevel3

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, contrived Extension that transfer files locally from one folder to another.

Step 1 -

...

  Initializing the OtelDemo Extension

...

Go ahead and navigate to a directory where you would like to store the Extension. Download the attached Extension template below.

View file
nameOtelDemoTemplate.zip
height150

Open up the terminal to that folder and run

Code Block
 uip template add <path to OtelDemoTemplate.zip>
Info
titleReference

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

Code Block
 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 Open up the terminal to that folder and run

Code Block
uip init -t OtelDemo <path to OtelDemoTemplate.zip> OtelDemoExt

This command should create a folder named OtelDemoExt with the Extension inside of it. 

Info
titleTemplate 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 We will test the Extension to the Controller using

Code Block
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:

  1. OtelDemoGetFiles
    Image Removed
  2. OtelDemoUploadFile
    Image Removed
  3. OtelDemoDeleteFiles
    Image Removed

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:

Image Removed

You can run the OtelDemoDeleteFiles task now, which will delete test1.txtthe UIP VSCode Plugin debugger for now. Once we have the Extension enhanced with Opentelemetry, we will test it in the Controller.

Go ahead and open the folder containing the Extension in VSCode. It is assumed that the new Universal Extension Bundle 2.1.0, containing API Level 1.5.0, is installed.

Once opened, press F5 and add a debug configuration as follows:

Code Block
titleconfigurations.yml
linenumberstrue
api:
  extension_start:
    - name: es1
      log_level: Inherited
      runtime_dir: /home/shrey/dev/extensions/test/OtelDemoTest
      fields:
        src_folder: /tmp/test_src
        dst_folder: /tmp/test_dst
        file_type:
          - txt

We will be transferring all *.txt files from /tmp/test_src to /tmp/test_dst. Ensure the source and destination directories exist, and the source folder contains a.txtb.txtc.zipd.jsone.yaml.

Debug the es1 target, and you should see a.txt and b.txt transferred to the /tmp/test_dst. Inspect the UIP Debug output channels to ensure everything worked as expected.

Next >