Giter Club home page Giter Club logo

wasm-practitioners-guide-to-observability's Introduction

Wasm Practitioners Guide to Observability

Setup

Install these tools, and follow the slides if you'd like! https://docs.google.com/presentation/d/1-BxJFaSeOWVLu18Nr26zDX-vvc8yEK9QYTAHi5gne5k/edit?usp=sharing

1. Install Jaeger (viewing OpenTelemetry data)

docker run -d --rm --name jaeger \
  -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
  -p 6831:6831/udp \
  -p 6832:6832/udp \
  -p 5778:5778 \
  -p 16686:16686 \
  -p 4317:4317 \
  -p 4318:4318 \
  -p 14250:14250 \
  -p 14268:14268 \
  -p 14269:14269 \
  -p 9411:9411 \
  jaegertracing/all-in-one:1.54

Run this at http://localhost:16686/ in your browser.

2. Run the Go host service (executes Wasm code)

cd src/host/module-runner

docker build --tag workshop-host .
docker run --network host workshop-host
# be sure to pass `--network host` here so that the Go application can reach Jaeger

This will start a server running at http://localhost:3000

3. Upload instrumented wasm code to the Go host service

# from the root of the repo

# upload the Rust-based wasm module, name it `rust-manual`
curl -F wasm=@src/guest/rust/rust.wasm "http://localhost:3000/upload?name=rust-manual"

# upload the Go-based wasm module, name it `go-manual`
curl -F wasm=@src/guest/go/main.wasm "http://localhost:3000/upload?name=go-manual"

4. Run instrumented wasm code on the Go host service

# run the Rust-based wasm module
curl -X POST "http://localhost:3000/run?name=rust-manual"

# run the Go-based wasm module
curl -X POST "http://localhost:3000/run?name=go-manual"

5. Auto-instrument Wasm code using Dylibso's instrumenting compiler

5.2 Instrument your module

Instrument your module by sending it in a HTTP multipart/form-data POST request to the compiler:

# Update the paths to the wasm module to instrument to use pre-built ones, or bring your own! Be sure to also set or fill-in $API_KEY
curl --fail -F [email protected] -H "Authorization: Bearer $API_KEY" \
  https://compiler-preview.dylibso.com/instrument > code.instr.wasm

Alternatively you can try out the pre-instrumented modules instead for the next step:

Go debug build instrumented

src/guest/modules/automatic/go/main.debug.instr.wasm

Rust debug build instrumented

src/guest/modules/automatic/rust/rust.debug.instr.wasm

5.3 Upload and run the auto-instrumented module

curl -F wasm=@src/guest/modules/automatic/go/main.debug.instr.wasm "http://localhost:3000/upload?name=go-automatic"

curl -X POST "http://localhost:3000/run?name=go-automatic"

As almost every function is instrumented, there should be much more output in Jaegar then we had from manual instrumentation.

5.4 Instrument your module with configuration

The compiler can optionally take configuration to allow or disallow certain functions explicitly, which helps to get a fine-grained trace or ignore certain functions altogether.

Let's also re-configure the adapter to change the SpanDuration and see how we can change the trace to better suit our needs when observing the behaviour of these programs.

See: https://dev.dylibso.com/docs/observe/instrumentation/automatic#configuring-the-automatic-instrumentation

curl --fail -F [email protected]  -F [email protected] \
  -H "Authorization: Bearer $API_KEY" \
  https://compiler-preview.dylibso.com/instrument > code.instr.wasm

or inline:

curl --fail -F [email protected] -F config='{"allowed": ["foo", "bar"]}' \
  -H "Authorization: Bearer $API_KEY" \
  https://compiler-preview.dylibso.com/instrument > code.instr.wasm

Alternatively you can try out the pre-instrumented modules with config:

Go

src/guest/modules/automatic/go/main.debug.config.instr.wasm

Rust

src/guest/modules/automatic/rust/rust.debug.config.instr.wasm

If you upload and run your module, you'll see that the instrumentation output has been greatly reduced.

6 Components

The Observe SDK can also run components.

6.1 Install cargo-component 0.70

cargo install [email protected]

6.2 Build a component using the Observe API

cd src/guest/components/manual/rust/

cargo component build

It should build to target/wasm32-wasi/debug/component-instr-command.wasm

Alternatively, the prebuilt component is available:

component-instr-command.wasm

6.3 Running the component

Only the Rust version of the Observe SDK currently has component support so we cannot use same host.

Navigate to src/host/component-runner

Run a prebuilt component:

cargo run ../../guest/components/manual/rust/component-instr-command.wasm

Or run the component you built:

cargo run ../../guest/components/manual/rust/target/wasm32-wasi/debug/component-instr-command.wasm

The output from this host is outputted to stdout. The message printed is a little cryptic, but there is a span named hello world. The message is an Open Telemetry Protobuf message in Rust debug format. In the future we plan on improving the OTEL adapter to be able to send to a collector as the go host does.

Automatic instrumentation of components is in the works.

wasm-practitioners-guide-to-observability's People

Contributors

g4vi avatar nilslice avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

wasm-practitioners-guide-to-observability's Issues

go collector cannot handle large otel output

Happens attempting to run guest auto-instr'd go modules such as:
src/guest/modules/automatic/go/main.debug.instr.wasm

Error does not occur when allowed functions have been configured (likely as output is much smaller then).

Length of /tmp/go-auto-debug is 6816442 bytes
2024/03/05 23:48:36 82054e25d011bc7e41a526c576092168
2024/03/05 23:48:36 stopped collector, sent to collector
2024/03/05 23:48:37 failed to upload wasm traces to otel endpoint rpc error: code = ResourceExhausted desc = grpc: received message larger than max (13529885 vs. 4194304)

span_tags appears on wrong span

On both go and rust manual examples, the discountPercentage and price end up on the UnmarshalProduct despite the UnmarshalProduct span ending first.

Rust:
image

Go:
image

Instrumented module with span_enter/span_exit produces an invalid trace

image

The rust module example:

    #[no_mangle]
    fn set_product(&mut self, input: &str) {
        span_enter("unmarshal_product");
        let product: Product = serde_json::from_str(input).unwrap_or_default();
        span_exit();

        if product.brand != "Apple" {
            span_tags(vec!["brand:unknown"])
        }

        span_tags(vec![
            &format!("price:{}", product.price),
            &format!("discountPercentage:{}", product.discount_percentage),
        ]);

        self.product_item = product;
    }

Host output:

Length of `/tmp/rust-auto-debug-config` is 4563639 bytes
2024/03/05 23:27:23 Expected call to 557 but found call to 0
2024/03/05 23:27:23 Expected call to 0 but found call to 559
2024/03/05 23:27:23 Expected call to 119 but found call to 0
2024/03/05 23:27:23 Expected call to 11 but found call to 0
2024/03/05 23:27:23 8391fdf66d2d7ab3de10e2672cbd38a8
2024/03/05 23:27:23 stopped collector, sent to collector

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.