lidavidm commented on a change in pull request #10260: URL: https://github.com/apache/arrow/pull/10260#discussion_r736934319
########## File path: cpp/src/arrow/util/tracing_internal.cc ########## @@ -0,0 +1,252 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "arrow/util/tracing_internal.h" + +#include <iostream> +#include <sstream> +#include <thread> + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4522) +#endif +#ifdef ARROW_WITH_OPENTELEMETRY +#include <opentelemetry/sdk/trace/batch_span_processor.h> +#include <opentelemetry/sdk/trace/recordable.h> +#include <opentelemetry/sdk/trace/span_data.h> +#include <opentelemetry/sdk/trace/tracer_provider.h> +#include <opentelemetry/trace/noop.h> +#include <opentelemetry/trace/provider.h> +#endif +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +#include "arrow/util/config.h" +#include "arrow/util/io_util.h" +#include "arrow/util/logging.h" +#include "arrow/util/make_unique.h" +#ifdef ARROW_JSON +#include "arrow/json/rapidjson_defs.h" +#include "rapidjson/ostreamwrapper.h" +#include "rapidjson/writer.h" +#endif + +namespace arrow { +namespace internal { +namespace tracing { + +namespace nostd = opentelemetry::nostd; +namespace otel = opentelemetry; + +constexpr char kTracingBackendEnvVar[] = "ARROW_TRACING_BACKEND"; + +namespace { + +#ifdef ARROW_WITH_OPENTELEMETRY +namespace sdktrace = opentelemetry::sdk::trace; +#ifdef ARROW_JSON +struct OwnedAttributeValueVisitor { + OwnedAttributeValueVisitor( + arrow::rapidjson::Writer<arrow::rapidjson::OStreamWrapper>& writer_) + : writer(writer_) {} + + void operator()(const std::string& arg) { writer.String(arg); } + + void operator()(const int32_t& arg) { writer.Int(arg); } + + void operator()(const uint32_t& arg) { writer.Uint(arg); } + + void operator()(const int64_t& arg) { writer.Int64(arg); } + + void operator()(const uint64_t& arg) { writer.Uint64(arg); } + + template <typename T> + void operator()(T&& arg) { + writer.Null(); + } + + arrow::rapidjson::Writer<arrow::rapidjson::OStreamWrapper>& writer; +}; + +/// Export spans as newline-delimited JSON. +class OStreamJsonSpanExporter : public sdktrace::SpanExporter { Review comment: The motivation here was to have a convenient way to just get a log file that we could then parse/analyze with something else. Hence: 1) Yes we are a library, but for development purposes it's easier to just have very basic configuration built in 2) On top of that, [the C++ and Python libraries do not interoperate](https://github.com/open-telemetry/community/discussions/734) which makes it rather inconvenient to use with PyArrow 3) The output of OStreamSpanExporter is very annoying to parse compared to JSON That said, the collector seems like it should mostly address all this. IIRC, I had some issues with getting it to point to our gRPC build and such and decided to just drop it for expediency but we should figure it out instead of doing something special. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
