import ballerina/http;

service /hello on new http:Listener(9090) {

    resource function get .(http:Request req) returns http:Response|error {
        http:Client clientEP = check new ("https://httpstat.us");
        http:Response resp = check clientEP->forward("/200", req);
        return resp;
    }
}

Trace logs

The HTTP trace logs can be used to monitor the HTTP traffic that goes in and out of Ballerina. To enable trace logs, the log level has to be set to TRACE using the runtime argument:
-Cballerina.http.traceLogConsole=true.
The configurations can be set in the Config.toml file for advanced use cases such as specifying the file path to save the trace logs and specifying the hostname and port of a socket service to publish the trace logs.

For more information on the underlying module, see the HTTP module.

import ballerina/http;
service /hello on new http:Listener(9090) {
    resource function get .(http:Request req) returns http:Response|error {
        http:Client clientEP = check new ("https://httpstat.us");
        http:Response resp = check clientEP->forward("/200", req);
        return resp;
    }
}
bal run http_trace_logs.bal -- -Cballerina.http.traceLogConsole=true
ballerina: HTTP trace log enabled
# In the logs, `http.downstream` refers to the HTTP traffic that flows between the client and Ballerina
# while `http.upstream` refers to the HTTP traffic that flows between Ballerina and the backend.
[2021-10-06 18:18:11,118] TRACE {http.tracelog.downstream} - [id: 0x91dfb8c7] REGISTERED
[2021-10-06 18:18:11,151] TRACE {http.tracelog.downstream} - [id: 0x91dfb8c7, correlatedSource: n/a, host:/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:50367] ACTIVE
[2021-10-06 18:18:11,187] TRACE {http.tracelog.downstream} - [id: 0x91dfb8c7, correlatedSource: n/a, host:/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:50367] INBOUND: DefaultHttpRequest(decodeResult: success, version: HTTP/1.1)
GET /hello HTTP/1.1
Host: localhost:9090
User-Agent: curl/7.64.1
Accept: */*
[2021-10-06 18:18:11,223] TRACE {http.tracelog.downstream} - [id: 0x91dfb8c7, correlatedSource: n/a, host:localhost/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:50367] INBOUND: EmptyLastHttpContent, 0B
[2021-10-06 18:18:11,225] TRACE {http.tracelog.downstream} - [id: 0x91dfb8c7, correlatedSource: n/a, host:localhost/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:50367] READ COMPLETE
[2021-10-06 18:18:11,418] TRACE {http.tracelog.upstream} - [id: 0xf7c32f4c] REGISTERED
[2021-10-06 18:18:11,418] TRACE {http.tracelog.upstream} - [id: 0xf7c32f4c] CONNECT: httpstat.us/172.67.134.121:80, null
[2021-10-06 18:18:11,661] TRACE {http.tracelog.upstream} - [id: 0xf7c32f4c, correlatedSource: n/a, host:/192.168.1.21:50368 - remote:httpstat.us/172.67.134.121:80] DEREGISTER
[2021-10-06 18:18:11,664] TRACE {http.tracelog.upstream} - [id: 0xf7c32f4c, correlatedSource: n/a, host:/192.168.1.21:50368 - remote:httpstat.us/172.67.134.121:80] ACTIVE
[2021-10-06 18:18:11,665] TRACE {http.tracelog.upstream} - [id: 0xf7c32f4c, correlatedSource: n/a, host:/192.168.1.21:50368 - remote:httpstat.us/172.67.134.121:80] UNREGISTERED
[2021-10-06 18:18:11,665] TRACE {http.tracelog.upstream} - [id: 0xf7c32f4c] REGISTERED
[2021-10-06 18:18:11,671] TRACE {http.tracelog.upstream} - [id: 0xf7c32f4c, correlatedSource: 0x91dfb8c7, host:/192.168.1.21:50368 - remote:httpstat.us/172.67.134.121:80] OUTBOUND: DefaultHttpRequest(decodeResult: success, version: HTTP/1.1)
GET /200 HTTP/1.1
Accept: */*
host: httpstat.us
user-agent: ballerina
connection: keep-alive
[2021-10-06 18:18:11,674] TRACE {http.tracelog.upstream} - [id: 0xf7c32f4c, correlatedSource: 0x91dfb8c7, host:/192.168.1.21:50368 - remote:httpstat.us/172.67.134.121:80] OUTBOUND: EmptyLastHttpContent, 0B
[2021-10-06 18:18:11,675] TRACE {http.tracelog.upstream} - [id: 0xf7c32f4c, correlatedSource: 0x91dfb8c7, host:/192.168.1.21:50368 - remote:httpstat.us/172.67.134.121:80] FLUSH
[2021-10-06 18:18:12,027] TRACE {http.tracelog.upstream} - [id: 0xf7c32f4c, correlatedSource: 0x91dfb8c7, host:/192.168.1.21:50368 - remote:httpstat.us/172.67.134.121:80] INBOUND: DefaultHttpResponse(decodeResult: success, version: HTTP/1.1)
HTTP/1.1 200 OK
Date: Wed, 06 Oct 2021 12:48:11 GMT
Content-Type: text/plain; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
cache-control: private
vary: Accept-Encoding
x-aspnetmvc-version: 5.1
access-control-allow-origin: *
access-control-expose-headers: Link, Content-Range, Location, WWW-Authenticate, Proxy-Authenticate, Retry-After
access-control-expose-headers: Request-Context
x-aspnet-version: 4.0.30319
request-context: appId=cid-v1:7585021b-2db7-4da6-abff-2cf23005f0a9
x-powered-by: ASP.NET
set-cookie: ARRAffinity=dd9ed9b645068a439255e4a6e0a4e0f2b5c11799187f1613a5766939d04a2bc0;Path=/;HttpOnly;Domain=httpstat.us
CF-Cache-Status: DYNAMIC
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=Df0k19O1x6RNB6Uc0hwC%2BFcQZS27%2BOuWb1JATwpu15Zhvdxc3Yd465533%2BuB2PIJKEBfRrCyHSgNLMiDje2EMkli18C83LScpe4czBPDKbUV77XLGuzwGdu9oGoCpQ%3D%3D"}],"group":"cf-nel","max_age":604800}
NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
Server: cloudflare
CF-RAY: 699f00a99def15af-EWR
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400, h3-28=":443"; ma=86400, h3-27=":443"; ma=86400
[2021-10-06 18:18:12,040] TRACE {http.tracelog.upstream} - [id: 0xf7c32f4c, correlatedSource: 0x91dfb8c7, host:/192.168.1.21:50368 - remote:httpstat.us/172.67.134.121:80] INBOUND: DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 6, cap: 6/6, unwrapped: PooledUnsafeDirectByteBuf(ridx: 1172, widx: 1177, cap: 2048)), decoderResult: success), 6B
200 OK
[2021-10-06 18:18:12,041] TRACE {http.tracelog.upstream} - [id: 0xf7c32f4c, correlatedSource: 0x91dfb8c7, host:/192.168.1.21:50368 - remote:httpstat.us/172.67.134.121:80] INBOUND: EmptyLastHttpContent, 0B
[2021-10-06 18:18:12,043] TRACE {http.tracelog.upstream} - [id: 0xf7c32f4c, correlatedSource: 0x91dfb8c7, host:/192.168.1.21:50368 - remote:httpstat.us/172.67.134.121:80] READ COMPLETE
[2021-10-06 18:18:12,046] TRACE {http.tracelog.downstream} - [id: 0x91dfb8c7, correlatedSource: n/a, host:localhost/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:50367] OUTBOUND: DefaultHttpResponse(decodeResult: success, version: HTTP/1.1)
HTTP/1.1 200 OK
Date: Wed, 06 Oct 2021 12:48:11 GMT
Content-Type: text/plain; charset=utf-8
Transfer-Encoding: chunked
cache-control: private
vary: Accept-Encoding
x-aspnetmvc-version: 5.1
access-control-allow-origin: *
access-control-expose-headers: Link, Content-Range, Location, WWW-Authenticate, Proxy-Authenticate, Retry-After
access-control-expose-headers: Request-Context
x-aspnet-version: 4.0.30319
request-context: appId=cid-v1:7585021b-2db7-4da6-abff-2cf23005f0a9
x-powered-by: ASP.NET
set-cookie: ARRAffinity=dd9ed9b645068a439255e4a6e0a4e0f2b5c11799187f1613a5766939d04a2bc0;Path=/;HttpOnly;Domain=httpstat.us
CF-Cache-Status: DYNAMIC
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=Df0k19O1x6RNB6Uc0hwC%2BFcQZS27%2BOuWb1JATwpu15Zhvdxc3Yd465533%2BuB2PIJKEBfRrCyHSgNLMiDje2EMkli18C83LScpe4czBPDKbUV77XLGuzwGdu9oGoCpQ%3D%3D"}],"group":"cf-nel","max_age":604800}
NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
CF-RAY: 699f00a99def15af-EWR
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400, h3-28=":443"; ma=86400, h3-27=":443"; ma=86400
server: cloudflare
[2021-10-06 18:18:12,048] TRACE {http.tracelog.downstream} - [id: 0x91dfb8c7, correlatedSource: n/a, host:localhost/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:50367] OUTBOUND: DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 6, cap: 6/6, unwrapped: PooledUnsafeDirectByteBuf(ridx: 1177, widx: 1177, cap: 2048)), decoderResult: success), 6B
200 OK
[2021-10-06 18:18:12,049] TRACE {http.tracelog.downstream} - [id: 0x91dfb8c7, correlatedSource: n/a, host:localhost/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:50367] FLUSH
[2021-10-06 18:18:12,054] TRACE {http.tracelog.downstream} - [id: 0x91dfb8c7, correlatedSource: n/a, host:localhost/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:50367] OUTBOUND: DefaultLastHttpContent(data: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 0, cap: 0), decoderResult: success), 0B
[2021-10-06 18:18:12,055] TRACE {http.tracelog.downstream} - [id: 0x91dfb8c7, correlatedSource: n/a, host:localhost/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:50367] FLUSH
[2021-10-06 18:18:12,057] TRACE {http.tracelog.downstream} - [id: 0x91dfb8c7, correlatedSource: n/a, host:localhost/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:50367] READ COMPLETE
[2021-10-06 18:18:12,058] TRACE {http.tracelog.downstream} - [id: 0x91dfb8c7, correlatedSource: n/a, host:localhost/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:50367] INACTIVE
[2021-10-06 18:18:12,061] TRACE {http.tracelog.downstream} - [id: 0x91dfb8c7, correlatedSource: n/a, host:localhost/0:0:0:0:0:0:0:1:9090 - remote:/0:0:0:0:0:0:0:1:50367] UNREGISTERED
# Invoke the service.
curl http://localhost:9090/hello
200 OK