Commit 508e1205 authored by Nane Kratzke's avatar Nane Kratzke
Browse files

Instrument hip-hop

parent 2a1f7d4d
This diff is collapsed.
This diff is collapsed.
import ballerina/http;
import ballerina/log;
import ballerina/config;
string astrosSvc = config:getAsString("ASTROS_SVC", "localhost:9090");
string positionSvc = config:getAsString("POSITION_SVC", "localhost:9090");
string passtimeSvc = config:getAsString("PASSTIME_SVC", "localhost:9090");
@http:ServiceConfig { basePath: "/" }
service space on new http:Listener(9090) {
@http:ResourceConfig { methods: ["GET"], path: "/" }
resource function index (http:Caller caller, http:Request req) returns @untainted error? {
log:printInfo(string `${ req.method } ${ req.rawPath } [${ req.userAgent }] by ${ caller.remoteAddress.toString() }`);
http:Response res = new;
check caller->redirect(res, 300, ["/space"]);
}
@http:ResourceConfig { methods: ["GET"], path: "/space" }
resource function alldata (http:Caller caller, http:Request req) returns @untainted error? {
log:printInfo(string `${ req.method } ${ req.rawPath } [${ req.userAgent }] by ${ caller.remoteAddress.toString() }`);
http:Client notify = new ("http://api.open-notify.org");
log:printInfo("Sending requests");
future<http:Response | error> astrosResponse = start notify->get("/astros");
future<http:Response | error> positionResponse = start notify->get("/position");
future<http:Response | error> passtimeResponse = start notify->get("/iss-pass.json?lat=0.001&lon=0.001");
log:printInfo("Awaiting answers");
http:Response | error astros = wait astrosResponse;
http:Response | error position = wait positionResponse;
http:Response | error passtime = wait passtimeResponse;
log:printInfo("Processing answers");
if (astros is error || position is error || passtime is error) {
log:printError("Could not load position or astro data from one or more endpoints");
if (astros is error) { log:printError(astros.reason()); }
if (position is error) { log:printError(position.reason()); }
if (passtime is error) { log:printError(passtime.reason()); }
check caller->internalServerError("Could not load data from one or more remote services");
} else {
json result = {
"astros": check astros.getJsonPayload(),
"position": check position.getJsonPayload(),
"passtime": check passtime.getJsonPayload()
};
http:Response res = new;
res.statusCode = 500;
res.setPayload(<@untained> result);
check caller->respond(res);
}
}
}
\ No newline at end of file
from flask import Flask, redirect, request
import requests, traceback, os
from elasticapm.contrib.flask import ElasticAPM
# A very boring and basic hip-hop-service to demonstrate
# observability via tracing.
service = os.environ.get('HIPHOP', 'hiphop')
tier = int(os.environ.get('TIER', '1'))
app = Flask(__name__)
apm = ElasticAPM(app,
service_name=os.environ.get('HIPHOP', 'hiphop'),
)
@app.route('/')
def index():
......
from flask import Flask, redirect, request, jsonify
import requests, os, json, logging
import elasticapm
from elasticapm.contrib.flask import ElasticAPM
# A very boring and basic space-service to demonstrate
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment