dylibso / observe-sdk

Continuous runtime observablity SDKs to monitor WebAssembly code.
https://dev.dylibso.com/docs/observe/overview
Apache License 2.0
156 stars 7 forks source link

feat: add manual instrumentation host functions to Go SDK #152

Closed mhmd-azeez closed 8 months ago

mhmd-azeez commented 8 months ago

After working on https://github.com/extism/go-sdk/pull/47, I realized that the Go SDK is missing these host functions:

  1. span_enter
  2. span_exit
  3. metric: stubbed out
  4. log: stubbed out
  5. span_tags (only exists in the Rust API)
    • host function: ✅
    • stdout: ✅
    • datadog: ✅
    • otel: ✅

The Rust SDK seems to be more complete, so I am basing my implementation on it

nilslice commented 8 months ago

Awesome, thank you @mhmd-azeez! Will take a look asap

mhmd-azeez commented 8 months ago
PS D:\dylibso\observe-sdk\go\bin\stdout> go run . "D:\dylibso\observe-sdk\observe-api\test\rust_guest.wasm"
2024/01/15 10:46:37  Call to main took 528.8µs
2024/01/15 10:46:37  Span tags: [user_id:123 world:hello]
2024/01/15 10:46:37    Call to run took 528.8µs
2024/01/15 10:46:37      Call to log_something took 0s
2024/01/15 10:46:37      Metric worlds.helloed:1|c Format 1
2024/01/15 10:46:37      Log Hello World 1
2024/01/15 10:46:37      Call to log_something took 0s
2024/01/15 10:46:37      Metric worlds.helloed:1|c Format 1
2024/01/15 10:46:37      Log Hello World 2
2024/01/15 10:46:37      Call to log_something took 0s
2024/01/15 10:46:37      Metric worlds.helloed:1|c Format 1
2024/01/15 10:46:37      Log Hello World 3
mhmd-azeez commented 8 months ago
PS D:\dylibso\observe-sdk\go\bin\otelstdout> go run . "D:\dylibso\observe-sdk\observe-api\test\rust_guest.wasm" | jq
{
  "resource_spans": [
    {
      "resource": {
        "attributes": [
          {
            "key": "service.name",
            "value": {
              "Value": {
                "StringValue": "golang"
              }
            }
          }
        ]
      },
      "scope_spans": [
        {
          "spans": [
            {
              "trace_id": "Hb4y85zbmzU7ZYx7TMQu3A==",
              "span_id": "35Wkp/0KIWo=",
              "name": "main",
              "kind": 1,
              "start_time_unix_nano": 1705305392272164300,
              "end_time_unix_nano": 1705305392272164300,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-main"
                    }
                  }
                },
                {
                  "key": "user_id",
                  "value": {
                    "Value": {
                      "StringValue": "123"
                    }
                  }
                },
                {
                  "key": "world",
                  "value": {
                    "Value": {
                      "StringValue": "hello"
                    }
                  }
                }
              ]
            },
            {
              "trace_id": "Hb4y85zbmzU7ZYx7TMQu3A==",
              "span_id": "CMh6L6C2R2g=",
              "parent_span_id": "35Wkp/0KIWo=",
              "name": "run",
              "kind": 1,
              "start_time_unix_nano": 1705305392272164300,
              "end_time_unix_nano": 1705305392272164300,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-run"
                    }
                  }
                }
              ]
            },
            {
              "trace_id": "Hb4y85zbmzU7ZYx7TMQu3A==",
              "span_id": "jVBdEHFklXA=",
              "parent_span_id": "CMh6L6C2R2g=",
              "name": "log_something",
              "kind": 1,
              "start_time_unix_nano": 1705305392272164300,
              "end_time_unix_nano": 1705305392272164300,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-log_something"
                    }
                  }
                }
              ]
            },
            {
              "trace_id": "Hb4y85zbmzU7ZYx7TMQu3A==",
              "span_id": "T3Ag7YUsjA8=",
              "parent_span_id": "CMh6L6C2R2g=",
              "name": "log_something",
              "kind": 1,
              "start_time_unix_nano": 1705305392272164300,
              "end_time_unix_nano": 1705305392272164300,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-log_something"
                    }
                  }
                }
              ]
            },
            {
              "trace_id": "Hb4y85zbmzU7ZYx7TMQu3A==",
              "span_id": "wrD9SH0shGU=",
              "parent_span_id": "CMh6L6C2R2g=",
              "name": "log_something",
              "kind": 1,
              "start_time_unix_nano": 1705305392272164300,
              "end_time_unix_nano": 1705305392272164300,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-log_something"
                    }
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}
bhelx commented 8 months ago

As we discussed in meeting. let's print out metrics and logs for the time being and note that they aren't sent to sink yet. we can circle back around on it. We may want to decide and build out some of this stuff before wasm i/o

mhmd-azeez commented 8 months ago

I have stubbed out the implementation for metrics and logs for now:

PS D:\dylibso\observe-sdk\go\bin\stdout> go run . "D:\dylibso\observe-sdk\observe-api\test\rust_guest.wasm"
2024/01/16 17:33:23 metric: worlds.helloed:1|c
2024/01/16 17:33:23 Hello World 1
2024/01/16 17:33:23 metric: worlds.helloed:1|c
2024/01/16 17:33:23 Hello World 2
2024/01/16 17:33:23 metric: worlds.helloed:1|c
2024/01/16 17:33:23 Hello World 3
2024/01/16 17:33:23  Call to main took 0s
2024/01/16 17:33:23  Span tags: [user_id:123 world:hello]
2024/01/16 17:33:23    Call to run took 0s
2024/01/16 17:33:23      Call to log_something took 0s
2024/01/16 17:33:23      Call to log_something took 0s
2024/01/16 17:33:23      Call to log_something took 0s
PS D:\dylibso\observe-sdk\go\bin\otelstdout> go run . "D:\dylibso\observe-sdk\observe-api\test\rust_guest.wasm" | jq
2024/01/16 17:33:39 metric: worlds.helloed:1|c
2024/01/16 17:33:39 Hello World 1
2024/01/16 17:33:39 metric: worlds.helloed:1|c
2024/01/16 17:33:39 Hello World 2
2024/01/16 17:33:39 metric: worlds.helloed:1|c
2024/01/16 17:33:39 Hello World 3
{
  "resource_spans": [
    {
      "resource": {
        "attributes": [
          {
            "key": "service.name",
            "value": {
              "Value": {
                "StringValue": "golang"
              }
            }
          }
        ]
      },
      "scope_spans": [
        {
          "spans": [
            {
              "trace_id": "Ou4yL9yUC4BQg95yJ+ewCg==",
              "span_id": "PPDLcpkhTSI=",
              "name": "main",
              "kind": 1,
              "start_time_unix_nano": 1705415619995863400,
              "end_time_unix_nano": 1705415619996366200,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-main"
                    }
                  }
                },
                {
                  "key": "user_id",
                  "value": {
                    "Value": {
                      "StringValue": "123"
                    }
                  }
                },
                {
                  "key": "world",
                  "value": {
                    "Value": {
                      "StringValue": "hello"
                    }
                  }
                }
              ]
            },
            {
              "trace_id": "Ou4yL9yUC4BQg95yJ+ewCg==",
              "span_id": "ke5RPsvFkyI=",
              "parent_span_id": "PPDLcpkhTSI=",
              "name": "run",
              "kind": 1,
              "start_time_unix_nano": 1705415619996366200,
              "end_time_unix_nano": 1705415619996366200,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-run"
                    }
                  }
                }
              ]
            },
            {
              "trace_id": "Ou4yL9yUC4BQg95yJ+ewCg==",
              "span_id": "PX+BGZP5mVE=",
              "parent_span_id": "ke5RPsvFkyI=",
              "name": "log_something",
              "kind": 1,
              "start_time_unix_nano": 1705415619996366200,
              "end_time_unix_nano": 1705415619996366200,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-log_something"
                    }
                  }
                }
              ]
            },
            {
              "trace_id": "Ou4yL9yUC4BQg95yJ+ewCg==",
              "span_id": "nlTNTMVIV2A=",
              "parent_span_id": "ke5RPsvFkyI=",
              "name": "log_something",
              "kind": 1,
              "start_time_unix_nano": 1705415619996366200,
              "end_time_unix_nano": 1705415619996366200,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-log_something"
                    }
                  }
                }
              ]
            },
            {
              "trace_id": "Ou4yL9yUC4BQg95yJ+ewCg==",
              "span_id": "sNWOxpH+OVY=",
              "parent_span_id": "ke5RPsvFkyI=",
              "name": "log_something",
              "kind": 1,
              "start_time_unix_nano": 1705415619996366200,
              "end_time_unix_nano": 1705415619996366200,
              "attributes": [
                {
                  "key": "function-name",
                  "value": {
                    "Value": {
                      "StringValue": "function-call-log_something"
                    }
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}