Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
28a5d7a2
Unverified
Commit
28a5d7a2
authored
Nov 14, 2021
by
Tim Neutkens
Committed by
GitHub
Nov 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite send-trace-to-jaeger in Rust (#31392)
parent
ce311204
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1049 additions
and
0 deletions
+1049
-0
Cargo.lock
scripts/send-trace-to-jaeger/Cargo.lock
+952
-0
Cargo.toml
scripts/send-trace-to-jaeger/Cargo.toml
+11
-0
main.rs
scripts/send-trace-to-jaeger/src/main.rs
+86
-0
No files found.
scripts/send-trace-to-jaeger/Cargo.lock
0 → 100644
View file @
28a5d7a2
This diff is collapsed.
Click to expand it.
scripts/send-trace-to-jaeger/Cargo.toml
0 → 100644
View file @
28a5d7a2
[package]
name
=
"send-trace-to-jaeger"
version
=
"0.1.0"
edition
=
"2021"
publish
=
false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde_json
=
"1.0.59"
reqwest
=
{
version
=
"0.11.6"
,
features
=
["blocking"]
}
\ No newline at end of file
scripts/send-trace-to-jaeger/src/main.rs
0 → 100644
View file @
28a5d7a2
use
reqwest
::
blocking
::
Client
;
use
serde_json
::{
Map
,
Number
,
Value
};
use
std
::
env
::
args
;
use
std
::
fs
::
File
;
use
std
::
io
::{
self
,
BufRead
};
use
std
::
path
::
Path
;
/// Read individual lines from a file.
fn
read_lines
<
P
>
(
filename
:
P
)
->
io
::
Result
<
io
::
Lines
<
io
::
BufReader
<
File
>>>
where
P
:
AsRef
<
Path
>
,
{
let
file
=
File
::
open
(
filename
)
?
;
Ok
(
io
::
BufReader
::
new
(
file
)
.lines
())
}
/// Log the url to view the trace in the browser.
fn
log_web_url
(
jaeger_web_ui_url
:
&
str
,
trace_id
:
&
str
)
{
println!
(
"Jaeger trace will be available on {}/trace/{}"
,
jaeger_web_ui_url
.to_string
(),
trace_id
.to_string
()
)
}
/// Send trace JSON to Jaeger using ZipKin API.
fn
send_json_to_zipkin
(
zipkin_api
:
&
str
,
value
:
String
)
{
let
client
=
Client
::
new
();
let
res
=
client
.post
(
zipkin_api
)
.header
(
"Content-Type"
,
"application/json"
)
.body
(
value
)
.send
()
.expect
(
"Failed to send request"
);
println!
(
"body = {:?}"
,
res
.text
());
}
fn
main
()
{
let
service_name
=
"nextjs"
;
let
ipv4
=
"127.0.0.1"
;
let
port
=
9411
;
let
zipkin_url
=
format!
(
"http://{}:{}"
,
ipv4
,
port
);
let
jaeger_web_ui_url
=
format!
(
"http://{}:16686"
,
ipv4
);
let
zipkin_api
=
format!
(
"{}/api/v2/spans"
,
zipkin_url
);
let
mut
logged_url
=
false
;
let
mut
local_endpoint
=
Map
::
new
();
local_endpoint
.insert
(
"serviceName"
.to_string
(),
Value
::
String
(
service_name
.to_string
()),
);
local_endpoint
.insert
(
"ipv4"
.to_string
(),
Value
::
String
(
ipv4
.to_string
()));
local_endpoint
.insert
(
"port"
.to_string
(),
Value
::
Number
(
Number
::
from
(
port
)));
let
first_arg
=
args
()
.nth
(
1
)
.expect
(
"Please provide a file name"
);
if
let
Ok
(
lines
)
=
read_lines
(
first_arg
)
{
for
line
in
lines
{
if
let
Ok
(
json_to_parse
)
=
line
{
let
v
=
match
serde_json
::
from_str
::
<
Vec
<
Value
>>
(
&
json_to_parse
)
{
Ok
(
v
)
=>
v
.into_iter
()
.map
(|
mut
data
|
{
if
!
logged_url
{
log_web_url
(
&
jaeger_web_ui_url
,
&
data
[
"traceId"
]
.to_string
());
logged_url
=
true
;
}
data
[
"localEndpoint"
]
=
Value
::
Object
(
local_endpoint
.clone
());
data
})
.collect
::
<
Value
>
(),
Err
(
e
)
=>
{
println!
(
"{}"
,
e
);
continue
;
}
};
let
json_map
=
serde_json
::
to_string
(
&
v
)
.expect
(
"Failed to serialize"
);
send_json_to_zipkin
(
&
zipkin_api
,
json_map
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment