Tracing Mobile App MQTT Traffic with Instana

  1. Set the “defaultHost” variable to point to my Message Gateway host.
  2. Edit viewDidLoad function to use the simpleSSLSetting function for connecting to the broker
  3. In the simpleSSLSetting function:
    - Set port to 443 (the route to my Message Gateway instance is using the HTTPS port
    - Ensure the Peername is set in the SSL settings as OpenShift handles routing using SNI (server name idenitifcation). This is done by adding the following line:
    mqtt!.sslSettings = [kCFStreamSSLPeerName as String : defaultHost as NSObject]
Add Mobile App to Instana
Name for Mobile App
URL and Key
  1. Select File -> Swift Packages -> Add Package Dependency -> Xcode project name.
  2. Enter the https://github.com/instana/iOSAgent repository.
  1. Added an import for the Instana library by adding the following at the start of the code:
    import InstanaAgent
  2. Added two variables to hold the Instana URL and Key named InstanaURL and InstanaKey.
  3. Added the following line to the didFinshLaunchingWithOptions function to set up Instana (you can see that I reference the variables created in the last step):
    Instana.setup(key: InstanaKey, reportingURL: InstanaURL)
  4. Added the following line to the didFinshLaunchingWithOptions function to set up set up some user details for the app:
    Instana.setUser(id: “aaa000zzz”, email: “tony@example.com”, name: “Tony Hickman”)
static func reportEvent(name: String, timestamp: Instana.Types.Milliseconds? = nil, duration: Instana.Types.Milliseconds? = nil, backendTracingID: String? = nil, error: Error? = nil, meta: [String: String]? = nil, viewName: String? = Instana.viewName)
Update TRACE function
TraceID Singleton
Updated sendMessage
  • Lines 63–66 create a structure to hold the data I want to pass as a JSON object and you can see the traceId and the text are separate elements
  • Line 68 creates the message populated with the message text and traceID
  • Lines 71–73 create a JSON String from the struct
  • Line 74 is a debug print statement so I could check the code when running in XCode :-)
  • Line 76 calls the Instana reportEvent SDK API to register the fact I am publishing an MQTT message
  • Line 77 does the actul MQTT publish
didPublishMessage handler
didReceiveMessage handler
  • Lines 111–113 define the structure for the chat message response which matches the structure passed i.e. has a traceID and the message text
  • Lines 116 and 117 parse the MQTT message into the structure so the data elements can be accessed
  • Lines 120–122 handle checking if the response is from NodeRED and if so calling the Instana SDK API to report the fact that we have received a chat response

--

--

--

I‘ve worked for IBM all of my career and am an avid technologist who is keen to get his hands dirty. My role affords me this opportunity and I share what I can

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

You should write a linter

Azure Function Github to Slack Pipeline

Bluehost Reviews — 10 Pros & Cons You Should Know Now

Easy modal newsletter signup form with Sendgrid, Python Django, Tailwind

Custom Annotation Processing with Spring Boot

PHP CRUD Application — Portfolio Piece

12 Reasons for React Native App Development Popularity

Binary Search Algorithm Pattern in Python

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tony Hickman

Tony Hickman

I‘ve worked for IBM all of my career and am an avid technologist who is keen to get his hands dirty. My role affords me this opportunity and I share what I can

More from Medium

Using AWS API Gateway to Build an End-to-end HTTP API

API Gateway + AWS Lambda + RDS based Serverless Service

Secure Authentication to Tekton Dashboard using OIDC

Simple File Manager using AWS EFS