Skip to content

Instantly share code, notes, and snippets.

@plexus
Created July 15, 2022 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plexus/a5acb82d6dad69fb4a334310dd82a7f1 to your computer and use it in GitHub Desktop.
Save plexus/a5acb82d6dad69fb4a334310dd82a7f1 to your computer and use it in GitHub Desktop.
{:paths
["src" "resources"]
:deps
{org.clojure/clojure {:mvn/version "1.11.0"}
protojure/protojure {:mvn/version "1.7.3"}}}
(ns repl-sessions.otel-grpc
(:require [io.opentelemetry.proto.logs.v1 :as proto-logs]
[io.opentelemetry.proto.collector.logs.v1 :as coll-logs]
[protojure.grpc.client.api :as api]
[protojure.grpc.client.providers.http2]
[clojure.core.async :as async]))
(def conn
(protojure.grpc.client.providers.http2/connect {:uri "http://0.0.0.0:4317"}))
(def input (async/chan))
(def output (async/chan))
(let [{:keys [status message] :as res}
@(api/invoke @conn {:service "opentelemetry.proto.collector.logs.v1.LogsService"
:method "Export"
:input {:f coll-logs/new-ExportLogsServiceRequest :ch input}
:output {:f coll-logs/pb->ExportLogsServiceResponse :ch output}})]
(def res res)
res)
;;;----------------------------------------------------------------------------------
;;; Generated by protoc-gen-clojure. DO NOT EDIT
;;;
;;; Message Implementation of package io.opentelemetry.proto.common.v1
;;;----------------------------------------------------------------------------------
(ns io.opentelemetry.proto.common.v1
(:require [protojure.protobuf.protocol :as pb]
[protojure.protobuf.serdes.core :as serdes.core]
[protojure.protobuf.serdes.complex :as serdes.complex]
[protojure.protobuf.serdes.utils :refer [tag-map]]
[protojure.protobuf.serdes.stream :as serdes.stream]
[clojure.set :as set]
[clojure.spec.alpha :as s]))
;;----------------------------------------------------------------------------------
;;----------------------------------------------------------------------------------
;; Forward declarations
;;----------------------------------------------------------------------------------
;;----------------------------------------------------------------------------------
(declare cis->AnyValue)
(declare ecis->AnyValue)
(declare new-AnyValue)
(declare cis->ArrayValue)
(declare ecis->ArrayValue)
(declare new-ArrayValue)
(declare cis->KeyValueList)
(declare ecis->KeyValueList)
(declare new-KeyValueList)
(declare cis->KeyValue)
(declare ecis->KeyValue)
(declare new-KeyValue)
(declare cis->InstrumentationScope)
(declare ecis->InstrumentationScope)
(declare new-InstrumentationScope)
;;----------------------------------------------------------------------------------
;;----------------------------------------------------------------------------------
;; AnyValue-value's oneof Implementations
;;----------------------------------------------------------------------------------
;;----------------------------------------------------------------------------------
(defn convert-AnyValue-value [origkeyval]
(cond
(get-in origkeyval [:value :string-value]) origkeyval
(get-in origkeyval [:value :bool-value]) origkeyval
(get-in origkeyval [:value :int-value]) origkeyval
(get-in origkeyval [:value :double-value]) origkeyval
(get-in origkeyval [:value :array-value]) (update-in origkeyval [:value :array-value] new-ArrayValue)
(get-in origkeyval [:value :kvlist-value]) (update-in origkeyval [:value :kvlist-value] new-KeyValueList)
(get-in origkeyval [:value :bytes-value]) origkeyval
:default origkeyval))
(defn write-AnyValue-value [value os]
(let [field (first value)
k (when-not (nil? field) (key field))
v (when-not (nil? field) (val field))]
(case k
:string-value (serdes.core/write-String 1 {:optimize false} v os)
:bool-value (serdes.core/write-Bool 2 {:optimize false} v os)
:int-value (serdes.core/write-Int64 3 {:optimize false} v os)
:double-value (serdes.core/write-Double 4 {:optimize false} v os)
:array-value (serdes.core/write-embedded 5 v os)
:kvlist-value (serdes.core/write-embedded 6 v os)
:bytes-value (serdes.core/write-Bytes 7 {:optimize false} v os)
nil)))
;;----------------------------------------------------------------------------------
;;----------------------------------------------------------------------------------
;; Message Implementations
;;----------------------------------------------------------------------------------
;;----------------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; AnyValue
;-----------------------------------------------------------------------------
(defrecord AnyValue-record [value]
pb/Writer
(serialize [this os]
(write-AnyValue-value (:value this) os))
pb/TypeReflection
(gettype [this]
"io.opentelemetry.proto.common.v1.AnyValue"))
(s/def ::AnyValue-spec (s/keys :opt-un []))
(def AnyValue-defaults {})
(defn cis->AnyValue
"CodedInputStream to AnyValue"
[is]
(->> (tag-map AnyValue-defaults
(fn [tag index]
(case index
1 [:value {:string-value (serdes.core/cis->String is)}]
2 [:value {:bool-value (serdes.core/cis->Bool is)}]
3 [:value {:int-value (serdes.core/cis->Int64 is)}]
4 [:value {:double-value (serdes.core/cis->Double is)}]
5 [:value {:array-value (ecis->ArrayValue is)}]
6 [:value {:kvlist-value (ecis->KeyValueList is)}]
7 [:value {:bytes-value (serdes.core/cis->Bytes is)}]
[index (serdes.core/cis->undefined tag is)]))
is)
(map->AnyValue-record)))
(defn ecis->AnyValue
"Embedded CodedInputStream to AnyValue"
[is]
(serdes.core/cis->embedded cis->AnyValue is))
(defn new-AnyValue
"Creates a new instance from a map, similar to map->AnyValue except that
it properly accounts for nested messages, when applicable.
"
[init]
{:pre [(if (s/valid? ::AnyValue-spec init) true (throw (ex-info "Invalid input" (s/explain-data ::AnyValue-spec init))))]}
(-> (merge AnyValue-defaults init)
(convert-AnyValue-value)
(map->AnyValue-record)))
(defn pb->AnyValue
"Protobuf to AnyValue"
[input]
(cis->AnyValue (serdes.stream/new-cis input)))
(def ^:protojure.protobuf.any/record AnyValue-meta {:type "io.opentelemetry.proto.common.v1.AnyValue" :decoder pb->AnyValue})
;-----------------------------------------------------------------------------
; ArrayValue
;-----------------------------------------------------------------------------
(defrecord ArrayValue-record [values]
pb/Writer
(serialize [this os]
(serdes.complex/write-repeated serdes.core/write-embedded 1 (:values this) os))
pb/TypeReflection
(gettype [this]
"io.opentelemetry.proto.common.v1.ArrayValue"))
(s/def ::ArrayValue-spec (s/keys :opt-un []))
(def ArrayValue-defaults {:values [] })
(defn cis->ArrayValue
"CodedInputStream to ArrayValue"
[is]
(->> (tag-map ArrayValue-defaults
(fn [tag index]
(case index
1 [:values (serdes.complex/cis->repeated ecis->AnyValue is)]
[index (serdes.core/cis->undefined tag is)]))
is)
(map->ArrayValue-record)))
(defn ecis->ArrayValue
"Embedded CodedInputStream to ArrayValue"
[is]
(serdes.core/cis->embedded cis->ArrayValue is))
(defn new-ArrayValue
"Creates a new instance from a map, similar to map->ArrayValue except that
it properly accounts for nested messages, when applicable.
"
[init]
{:pre [(if (s/valid? ::ArrayValue-spec init) true (throw (ex-info "Invalid input" (s/explain-data ::ArrayValue-spec init))))]}
(-> (merge ArrayValue-defaults init)
(cond-> (some? (get init :values)) (update :values #(map new-AnyValue %)))
(map->ArrayValue-record)))
(defn pb->ArrayValue
"Protobuf to ArrayValue"
[input]
(cis->ArrayValue (serdes.stream/new-cis input)))
(def ^:protojure.protobuf.any/record ArrayValue-meta {:type "io.opentelemetry.proto.common.v1.ArrayValue" :decoder pb->ArrayValue})
;-----------------------------------------------------------------------------
; KeyValueList
;-----------------------------------------------------------------------------
(defrecord KeyValueList-record [values]
pb/Writer
(serialize [this os]
(serdes.complex/write-repeated serdes.core/write-embedded 1 (:values this) os))
pb/TypeReflection
(gettype [this]
"io.opentelemetry.proto.common.v1.KeyValueList"))
(s/def ::KeyValueList-spec (s/keys :opt-un []))
(def KeyValueList-defaults {:values [] })
(defn cis->KeyValueList
"CodedInputStream to KeyValueList"
[is]
(->> (tag-map KeyValueList-defaults
(fn [tag index]
(case index
1 [:values (serdes.complex/cis->repeated ecis->KeyValue is)]
[index (serdes.core/cis->undefined tag is)]))
is)
(map->KeyValueList-record)))
(defn ecis->KeyValueList
"Embedded CodedInputStream to KeyValueList"
[is]
(serdes.core/cis->embedded cis->KeyValueList is))
(defn new-KeyValueList
"Creates a new instance from a map, similar to map->KeyValueList except that
it properly accounts for nested messages, when applicable.
"
[init]
{:pre [(if (s/valid? ::KeyValueList-spec init) true (throw (ex-info "Invalid input" (s/explain-data ::KeyValueList-spec init))))]}
(-> (merge KeyValueList-defaults init)
(cond-> (some? (get init :values)) (update :values #(map new-KeyValue %)))
(map->KeyValueList-record)))
(defn pb->KeyValueList
"Protobuf to KeyValueList"
[input]
(cis->KeyValueList (serdes.stream/new-cis input)))
(def ^:protojure.protobuf.any/record KeyValueList-meta {:type "io.opentelemetry.proto.common.v1.KeyValueList" :decoder pb->KeyValueList})
;-----------------------------------------------------------------------------
; KeyValue
;-----------------------------------------------------------------------------
(defrecord KeyValue-record [key value]
pb/Writer
(serialize [this os]
(serdes.core/write-String 1 {:optimize true} (:key this) os)
(serdes.core/write-embedded 2 (:value this) os))
pb/TypeReflection
(gettype [this]
"io.opentelemetry.proto.common.v1.KeyValue"))
(s/def :io.opentelemetry.proto.common.v1.KeyValue/key string?)
(s/def ::KeyValue-spec (s/keys :opt-un [:io.opentelemetry.proto.common.v1.KeyValue/key ]))
(def KeyValue-defaults {:key "" })
(defn cis->KeyValue
"CodedInputStream to KeyValue"
[is]
(->> (tag-map KeyValue-defaults
(fn [tag index]
(case index
1 [:key (serdes.core/cis->String is)]
2 [:value (ecis->AnyValue is)]
[index (serdes.core/cis->undefined tag is)]))
is)
(map->KeyValue-record)))
(defn ecis->KeyValue
"Embedded CodedInputStream to KeyValue"
[is]
(serdes.core/cis->embedded cis->KeyValue is))
(defn new-KeyValue
"Creates a new instance from a map, similar to map->KeyValue except that
it properly accounts for nested messages, when applicable.
"
[init]
{:pre [(if (s/valid? ::KeyValue-spec init) true (throw (ex-info "Invalid input" (s/explain-data ::KeyValue-spec init))))]}
(-> (merge KeyValue-defaults init)
(cond-> (some? (get init :value)) (update :value new-AnyValue))
(map->KeyValue-record)))
(defn pb->KeyValue
"Protobuf to KeyValue"
[input]
(cis->KeyValue (serdes.stream/new-cis input)))
(def ^:protojure.protobuf.any/record KeyValue-meta {:type "io.opentelemetry.proto.common.v1.KeyValue" :decoder pb->KeyValue})
;-----------------------------------------------------------------------------
; InstrumentationScope
;-----------------------------------------------------------------------------
(defrecord InstrumentationScope-record [name version attributes dropped-attributes-count]
pb/Writer
(serialize [this os]
(serdes.core/write-String 1 {:optimize true} (:name this) os)
(serdes.core/write-String 2 {:optimize true} (:version this) os)
(serdes.complex/write-repeated serdes.core/write-embedded 3 (:attributes this) os)
(serdes.core/write-UInt32 4 {:optimize true} (:dropped-attributes-count this) os))
pb/TypeReflection
(gettype [this]
"io.opentelemetry.proto.common.v1.InstrumentationScope"))
(s/def :io.opentelemetry.proto.common.v1.InstrumentationScope/name string?)
(s/def :io.opentelemetry.proto.common.v1.InstrumentationScope/version string?)
(s/def :io.opentelemetry.proto.common.v1.InstrumentationScope/dropped-attributes-count int?)
(s/def ::InstrumentationScope-spec (s/keys :opt-un [:io.opentelemetry.proto.common.v1.InstrumentationScope/name :io.opentelemetry.proto.common.v1.InstrumentationScope/version :io.opentelemetry.proto.common.v1.InstrumentationScope/dropped-attributes-count ]))
(def InstrumentationScope-defaults {:name "" :version "" :attributes [] :dropped-attributes-count 0 })
(defn cis->InstrumentationScope
"CodedInputStream to InstrumentationScope"
[is]
(->> (tag-map InstrumentationScope-defaults
(fn [tag index]
(case index
1 [:name (serdes.core/cis->String is)]
2 [:version (serdes.core/cis->String is)]
3 [:attributes (serdes.complex/cis->repeated ecis->KeyValue is)]
4 [:dropped-attributes-count (serdes.core/cis->UInt32 is)]
[index (serdes.core/cis->undefined tag is)]))
is)
(map->InstrumentationScope-record)))
(defn ecis->InstrumentationScope
"Embedded CodedInputStream to InstrumentationScope"
[is]
(serdes.core/cis->embedded cis->InstrumentationScope is))
(defn new-InstrumentationScope
"Creates a new instance from a map, similar to map->InstrumentationScope except that
it properly accounts for nested messages, when applicable.
"
[init]
{:pre [(if (s/valid? ::InstrumentationScope-spec init) true (throw (ex-info "Invalid input" (s/explain-data ::InstrumentationScope-spec init))))]}
(-> (merge InstrumentationScope-defaults init)
(cond-> (some? (get init :attributes)) (update :attributes #(map new-KeyValue %)))
(map->InstrumentationScope-record)))
(defn pb->InstrumentationScope
"Protobuf to InstrumentationScope"
[input]
(cis->InstrumentationScope (serdes.stream/new-cis input)))
(def ^:protojure.protobuf.any/record InstrumentationScope-meta {:type "io.opentelemetry.proto.common.v1.InstrumentationScope" :decoder pb->InstrumentationScope})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment