main.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. #include <cstdio>
  4. #include <fstream> // IWYU pragma: keep
  5. #include <iostream>
  6. #include <iterator>
  7. #include <memory>
  8. #include <string>
  9. #include "opentelemetry/plugin/dynamic_load.h"
  10. #include "opentelemetry/plugin/factory.h"
  11. #include "opentelemetry/trace/tracer.h"
  12. int main(int argc, char *argv[])
  13. {
  14. if (argc != 3)
  15. {
  16. std::cerr << "Usage: load_plugin <plugin> <config>\n";
  17. return -1;
  18. }
  19. std::string error_message;
  20. auto factory = opentelemetry::plugin::LoadFactory(argv[1], error_message);
  21. if (factory == nullptr)
  22. {
  23. std::cerr << "Failed to load opentelemetry plugin: " << error_message << "\n";
  24. return -1;
  25. }
  26. std::ifstream config_in{argv[2]};
  27. if (!config_in.good())
  28. {
  29. std::perror("Failed to open config file");
  30. return -1;
  31. }
  32. std::string config{std::istreambuf_iterator<char>{config_in}, std::istreambuf_iterator<char>{}};
  33. auto tracer = factory->MakeTracer(config, error_message);
  34. if (tracer == nullptr)
  35. {
  36. std::cerr << "Failed to make tracer: " << error_message << "\n";
  37. return -1;
  38. }
  39. auto span = tracer->StartSpan("abc");
  40. return 0;
  41. }