Send traces to OpenTelemetry collector - open-telemetry

I am currently trying to send data to an OpenTelemetry OTLP collector. I cannot use any provided libraries because the application is written in Smalltalk. I have the span and trace data already. What I am missing is a way to get that data from my application to the collector. My idea was to just simply send the data as a JSON String, but I’m not able to find any examples.
Can somebody provide a example request?

Minimal curl example:
curl -H "Content-Type: application/json" \
-d #trace.json \
<collector-base-url>/v1/traces
Correct Content-Type header and /v1/traces path. Of course OTEL collector may have enabled some auth, then also auth must be provided in the request (basic auth, api key, ...).
Keep in mind: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlphttp
JSON format is Experimental
JSON format is working fine with recent OTEL collector versions, based on my personal experience. But it is still experimental format only. Serious stable implementation will need OTLP/HTTP Protobuf payloads encoded in binary format.

Related

How to send XML file request using Capybara, and check response for correct parameters

I am writing acceptance tests using capybara/rspec. And I want in one of my tests send request using XML file and check that it got correct parameters in response. Do you know how I can write it please?
For now I send my request using curl.
curl -X POST -H 'Content-Type: application/xml' -H 'Authorization: Basic example' http://example/example --data-binary #request.xml
But I want to automate it using Capybara/rspec
You don't do this with Capybara. Capybara is used for tests that replicate what a user would do via a browser. As such it interacts with elements in the browser and the page generates the requests a user would trigger. For what you want to test you should be looking at request specs (they don't use Capybara) which are aimed at testing APIs, etc. and allow for posts of random data to endpoints - https://relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec

How do you configure AWS API Gateway HTTP GET to return the BASE64 string as binary data?

I am trying to send binary data from my AWS Lambda function as a response to an AWS Gateway GET Method that DOES NOT use Lambda Proxy integration. I have tried all sorts of variations but still can't make it work, although I feel like I am close.
My API Gateway HTTP request is returning:
But what I want is is the actual binary data:
I did attempt using a mapping template, but was unsuccessful due to my lack of understanding the templating syntax/behavior(I tried $util.base64Decode($input.body) but that produced a server error).
But I wasn't sure if that was even necessary since I have the content handling set to Convert to binary.
I ran into this problem but I used a proxy url. Make sure to enable Binary Media Types. Also do not forget to deploy your changes, simply saving is not enough. Also make sure you have the correct content type in the header with client sending the payload.

Apache Nifi : How to pass post params and capture response from post API - traditional non rest, non json API

I'm trying to pull data from a post API that expects authentication and request parameters as part of the request body. I guess, what they do is access the data from the post variables.
What I have seen so far in documentation is how to send POST via JSON or headers. In my case, no headers just the post body parameters.
call to this api via curl --data option works just fine.
curl --data "username=xyz&password=xyz&function=xyz" http://example.com/api.php
How can I replicate above call in nifi?
I have tried multiple methods without success. Latest has been Generate flow file, update attributes (where i fill in the parameters), invoke http then putfile.
But I'm getting errors - the api is not abe to authenticate my request.
Thanks
If you need to send the following data in body, then put it into content of your flowfile.
username=xyz&password=xyz&function=xyz
The easiest way to put it into the Custom Text property of the GenerateFlowFile processor.
Usually for this kind of body you have to provide content type header:
content-type: application/x-www-form-urlencoded
If you don't need any additional headers then you don't have to define any additional attributes of the flow file.

http authentication using apiary / api blueprint

Just dipping my toes into Apiary and API Blueprint, and having some problems with passing in some basic http authentication.
On an initial call, the API creates a token for any given user that needs to be used with any subsequent call. My problem is how to mark-up that authentication so it works with the Apiary production request.
The command-line curl (that works) is (in obfuscated code) this...
curl --user name#somewhere.com:tokenGoesHere http://test.server.uri/API/getUserInfo
So, how do I convert that curl command into the equivalent API Blueprint format?
Unfortunately there's no way, at the moment, to specify authentication/authorisation in APIBlueprint.
It's in the roadmap, but unfortunately we can't give you any precise ETA on that.
You might want to read our help page on the argument as well.

batch http requests

Does anyone know a standard way to batch http requests?
Meaning - sending multiple http atomic requests in one round trip?
We need such mechanism in our REST API implementation for performance reasons. This kind of mechanism can reduce dramatically the number of round trips that the client needs to perform to consume the API.
Thanks in advance,
Shay
Define a new resource that contains the data the client wants. See http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven#comment-743
There's an official HTTP way to do that which is called HTTP Pipelining. But you may have more problems with the browser side than with the server-side. So you may be able to use it if you have a hig-level of control on the client side only.
XHR does not always allow pipeling, and AFAIK you have no control of the HTTP tunneling with Javascript. So a basic ajax-jQuery implementation cannot exists. But you may find some advanced things with Comet and the Bayeux protocol, emulating bi-directionnal long-term tcp-connections, where you will certainly reduce the tcp round trips.
I'm not a comet specialist, but you may find useful informations on this Comet & HTTP Pipeling article, to my understanding most of this is highly experimental, but at least you could have a nice fallback with 'classical' comet when HTTP Pipelining is not available. This would maybe need a retag or a new question.
That's a problem with REST. They are at entity level. The REST idea is to have each URL uniquely identify a resource.
Of course you can introduce aggregated resource. For ex, www.yoursite.com/customerA?include=Orders,Faults,Incidents
This returns the XML for CustomerA but also returns the Orders, faults, Incidents of the customer as embedded collection.
If you're looking at REST based services or an API of some kind. There is some beginnings of a standard here http://www.odata.org/documentation/odata-version-3-0/batch-processing/
And an implementation by Google here https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch
If using dedicated 'aggregate' resources as fumanchu said above does not work for you, you can also try if you can move representations of less volatile resources to caches to reduce load on your system. For example: HTML pages on the 'human' Web often include loads and loads of images and the many sub request are of no concern there.
CURL
The build 17063 of windows 10 (and the following versions) are coming with CURL command:
curl -X POST -H "Content-Type: application/json" -d "{\"name\": \"myname\", \"email\": \"some#example.com\"}' https://example/contact
winHttpJs.bat
call winhttpjs.bat "http://requestb.in/xxxxxx" -method POST -header hdrs.txt -reportfile reportfile2.txt
call winhttpjs.bat "http://requestb.in/xxxxxx" -method GET -header hdrs.txt -reportfile reportfile3.txt -saveTo c:\somezip.zip
call winhttpjs.bat "http://requestb.in/xxxxxx" -method POST -header hdrs.txt -reportfile reportfile2.txt -saveTo responsefile2 -ua "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36" -body-file some.json
It does not support multi-part requests at the moment ,i'm planning to add such a thing but I don't know when i'll have the time.
You create batch requests by calling new_batch_http_request() on your service object, which returns a BatchHttpRequest object, and then calling add() for each request you want to execute. You may pass in a callback with each request that is called with the response to that request. The callback function arguments are a unique request identifier for each API call, a response object which contains the API call response, and an exception object which may be set to an exception raised by the API call. After you've added the requests, you call execute() to make the requests. The execute() function blocks until all callbacks have been called.
References:
You can try this too https://developers.google.com/api-client
library/python/guide/batch
https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch

Resources