Skip to content

Commit 670ec10

Browse files
Tracing docs (#331)
--------- Co-authored-by: mehrotra234 <[email protected]>
1 parent e873509 commit 670ec10

File tree

4 files changed

+64
-10
lines changed

4 files changed

+64
-10
lines changed

docs/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ WORKDIR /app
55
COPY docs/quick-start /app/src/app/docs/quick-start
66
COPY docs/public /app/public
77
COPY docs/advanced-guide /app/src/app/docs/advanced-guide
8+
COPY docs/references /app/src/app/docs/references
89
COPY docs/page.md /app/src/app/docs
910
COPY docs/navigation.js /app/src/lib
1011

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Custom Spans In Tracing
2+
3+
GoFr's built-in tracing provides valuable insights into your application's behavior. However, sometimes you might need
4+
even more granular details about specific operations within your application. This is where `custom spans` come in.
5+
6+
## How it helps?
7+
By adding custom spans in traces to your requests, you can:
8+
9+
- **Gain granular insights:** Custom spans allow you to track specific operations or functions within your application,
10+
providing detailed performance data.
11+
- **Identify bottlenecks:** By analyzing custom spans, you can pinpoint areas of your code that may be causing
12+
performance bottlenecks or inefficiencies.
13+
- **Improve debugging:** Custom spans enhance your ability to debug issues by providing visibility into the execution
14+
flow of your application.
15+
16+
## Adding Custom Spans:
17+
18+
To add a custom trace to a request, you can use the `Trace()` method of GoFr context, which takes the name of the span as an argument
19+
and returns a trace.Span.
20+
21+
### Usage
22+
23+
```go
24+
func MyHandler(c context.Context) error {
25+
span := c.Trace("my-custom-span")
26+
defer span.Close()
27+
28+
// Do some work here
29+
return nil
30+
}
31+
```
32+
33+
In this example, **my-custom-span** is the name of the custom span that you want to add to the request.
34+
The defer statement ensures that the span is closed even if an error occurs to ensure that the trace is properly recorded.
35+
36+
37+

docs/navigation.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const navigation = [
2020
{ title: 'Monitoring Service Health', href: '/docs/advanced-guide/monitoring-service-health' },
2121
// { title: 'Supporting OAuth', href: '/docs/advanced-guide/oauth' },
2222
{ title: 'Circuit Breaker Support', href: '/docs/advanced-guide/circuit-breaker' },
23+
{ title: 'Custom Spans in Tracning', href: '/docs/advanced-guide/custom-spans-in-tracing' },
2324
// { title: 'Writing gRPC Server', href: '/docs/advanced-guide/grpc' },
2425
// { title: 'Creating a Static File Server', href: '/docs/advanced-guide/static-file-server' },
2526
// { title: 'WebSockets', href: '/docs/advanced-guide/websockets' },

docs/quick-start/observability/page.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,32 @@ Now that you have created your server, lets see how GoFr by default manages obse
8181

8282
GoFr also provides supports to create requirement specific metrics using [custom metrics](/docs/advanced-guide/publishing-custom-metrics).
8383

84-
8584
## Tracing
85+
Tracing is a powerful tool for gaining insights into your application's behaviour, identifying bottlenecks, and improving
86+
system performance. A trace is a tree of spans. It is a collective of observable signals showing the path of work
87+
through a system. A trace on its own is distinguishable by a `TraceID`.
8688

87-
GoFr adds traces by default for all the request and response,which allows you to export it to zipkin by adding the configs.
88-
It allows to monitor the request going through different parts of application like database, handler etc.
89+
In complex distributed systems, understanding how requests flow through the system is crucial for troubleshooting performance
90+
issues and identifying bottlenecks. Traditional logging approaches often fall short, providing limited visibility into
91+
the intricate interactions between components.
8992

90-
To see the traces install zipkin image using the following docker command
9193

92-
### Setup
94+
To know more about Tracing click [here](https://opentelemetry.io/docs/concepts/signals/#traces).
9395

94-
```bash
95-
docker run --name gofr-zipkin -p 2005:9411 -d openzipkin/zipkin:latest
96-
```
9796

98-
### Configuration & Usage
97+
### Automated Tracing in GoFr
98+
GoFr makes it easy to use tracing by automatically adding traces to all requests and responses. GoFr uses
99+
[OpenTelemetry](https://opentelemetry.io/docs/concepts/what-is-opentelemetry/), a popular tracing framework, to
100+
automatically add traces to all requests and responses.
101+
102+
**Automatic Correlation ID Propagation:**
103+
104+
When a request enters your GoFr application, GoFr automatically generates a correlation ID X-Correlation-ID and adds it
105+
to the request headers. This correlation ID is then propagated to all downstream requests. This means that you can track
106+
a request as it travels through your distributed system by simply looking at the correlation ID in the request headers.
107+
108+
109+
### Configuration & Usage
99110

100111
Add Tracer configs in `.env` file, your .env will be updated to
101112

@@ -112,12 +123,16 @@ Now that you have created your server, lets see how GoFr by default manages obse
112123
DB_NAME=test_db
113124
DB_PORT=3306
114125

126+
# tracing configs
115127
TRACER_HOST=localhost
116128
TRACER_PORT=2005
117129

118130
LOG_LEVEL=DEBUG
119131
```
120132

121-
Open [zipkin](http://localhost:2005/zipkin/) and search by TraceID (correlationID) to see the trace.
133+
> **NOTE:** If the value of `TRACER_PORT` is not
134+
provided, gofr uses port `9411` by default.
135+
136+
Open [zipkin](http://localhost:2005/zipkin/) and search by TraceID (correlationID) to see the trace.
122137

123138
{% figure src="/quick-start-trace.png" alt="Pretty Printed Logs" /%}

0 commit comments

Comments
 (0)