Skip to content

Commit 1f6090d

Browse files
committed
Move common code to common folder
1 parent 23abff8 commit 1f6090d

File tree

17 files changed

+158
-118
lines changed

17 files changed

+158
-118
lines changed

CMakeLists.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,28 @@ endif()
7373
set(TRACE_API_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/trace/include)
7474
set(CONTEXT_API_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/context/include)
7575
set(BAGGAGE_API_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/baggage/include)
76+
set(COMMON_API_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/common/include)
7677
set(TRACE_SDK_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sdk/trace/include)
78+
set(COMMON_SDK_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sdk/common/include)
7779
set(OTLP_EXPORTER_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/include)
78-
set(OPENTELEMETRY_PROXY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} ${TRACE_API_INCLUDE_DIR} ${CONTEXT_API_INCLUDE_DIR} ${BAGGAGE_API_INCLUDE_DIR} ${TRACE_SDK_INCLUDE_DIR} ${OTLP_EXPORTER_INCLUDE_DIR} ${OPENTELEMETRY_CPP_INCLUDE_DIRS})
80+
set(OPENTELEMETRY_PROXY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} ${TRACE_API_INCLUDE_DIR} ${CONTEXT_API_INCLUDE_DIR} ${BAGGAGE_API_INCLUDE_DIR} ${COMMON_API_INCLUDE_DIR} ${TRACE_SDK_INCLUDE_DIR} ${COMMON_SDK_INCLUDE_DIR} ${OTLP_EXPORTER_INCLUDE_DIR} ${OPENTELEMETRY_CPP_INCLUDE_DIRS})
7981

8082
set(OPENTELEMETRY_PROXY_FACTORY_CLASS_NAME OtelMatlabProxyFactory)
8183
set(OPENTELEMETRY_PROXY_FACTORY_SOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR})
8284
set(TRACE_API_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/trace/src)
8385
set(CONTEXT_API_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/context/src)
8486
set(BAGGAGE_API_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/baggage/src)
87+
set(COMMON_API_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/api/common/src)
8588
set(TRACE_SDK_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sdk/trace/src)
89+
set(COMMON_SDK_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sdk/common/src)
8690
set(OTLP_EXPORTER_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/src)
8791
set(OPENTELEMETRY_PROXY_SOURCES
8892
${OPENTELEMETRY_PROXY_FACTORY_SOURCES_DIR}/${OPENTELEMETRY_PROXY_FACTORY_CLASS_NAME}.cpp
8993
${TRACE_API_SOURCE_DIR}/TracerProviderProxy.cpp
9094
${TRACE_API_SOURCE_DIR}/TracerProxy.cpp
9195
${TRACE_API_SOURCE_DIR}/SpanProxy.cpp
9296
${TRACE_API_SOURCE_DIR}/SpanContextProxy.cpp
93-
${TRACE_API_SOURCE_DIR}/attribute.cpp
97+
${COMMON_API_SOURCE_DIR}/attribute.cpp
9498
${CONTEXT_API_SOURCE_DIR}/TextMapPropagatorProxy.cpp
9599
${CONTEXT_API_SOURCE_DIR}/CompositePropagatorProxy.cpp
96100
${CONTEXT_API_SOURCE_DIR}/TextMapCarrierProxy.cpp
@@ -99,7 +103,8 @@ set(OPENTELEMETRY_PROXY_SOURCES
99103
${TRACE_SDK_SOURCE_DIR}/TracerProviderProxy.cpp
100104
${TRACE_SDK_SOURCE_DIR}/SimpleSpanProcessorProxy.cpp
101105
${TRACE_SDK_SOURCE_DIR}/BatchSpanProcessorProxy.cpp
102-
${TRACE_SDK_SOURCE_DIR}/ParentBasedSamplerProxy.cpp)
106+
${TRACE_SDK_SOURCE_DIR}/ParentBasedSamplerProxy.cpp
107+
${COMMON_SDK_SOURCE_DIR}/resource.cpp)
103108
if(WITH_OTLP_HTTP)
104109
set(OPENTELEMETRY_PROXY_SOURCES ${OPENTELEMETRY_PROXY_SOURCES}
105110
${OTLP_EXPORTER_SOURCE_DIR}/OtlpHttpSpanExporterProxy.cpp)
@@ -215,7 +220,7 @@ libmexclass_client_install(
215220
set(TRACE_API_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/api/trace/+opentelemetry)
216221
set(CONTEXT_API_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/api/context/+opentelemetry)
217222
set(BAGGAGE_API_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/api/baggage/+opentelemetry)
218-
set(UTILS_API_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/api/utils/+opentelemetry)
223+
set(COMMON_API_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/api/common/+opentelemetry)
219224
set(TRACE_SDK_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/sdk/trace/+opentelemetry)
220225
set(DEFAULT_EXPORTER_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/+opentelemetry/+exporters/+otlp/defaultSpanExporter.m)
221226
set(OTLP_HTTP_EXPORTER_MATLAB_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/exporters/otlp/+opentelemetry/+exporters/+otlp/OtlpHttpSpanExporter.m)
@@ -226,7 +231,7 @@ set(OTLP_EXPORTERS_DIR +opentelemetry/+exporters/+otlp)
226231
install(DIRECTORY ${TRACE_API_MATLAB_SOURCES} DESTINATION .)
227232
install(DIRECTORY ${CONTEXT_API_MATLAB_SOURCES} DESTINATION .)
228233
install(DIRECTORY ${BAGGAGE_API_MATLAB_SOURCES} DESTINATION .)
229-
install(DIRECTORY ${UTILS_API_MATLAB_SOURCES} DESTINATION .)
234+
install(DIRECTORY ${COMMON_API_MATLAB_SOURCES} DESTINATION .)
230235
install(DIRECTORY ${TRACE_SDK_MATLAB_SOURCES} DESTINATION .)
231236
install(FILES ${DEFAULT_EXPORTER_MATLAB_SOURCES} DESTINATION ${OTLP_EXPORTERS_DIR})
232237
if(WITH_OTLP_HTTP)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2023 The MathWorks, Inc.
2+
3+
#pragma once
4+
5+
#include "opentelemetry/common/attribute_value.h"
6+
#include "opentelemetry/nostd/string_view.h"
7+
8+
#include <list>
9+
10+
namespace common = opentelemetry::common;
11+
namespace nostd = opentelemetry::nostd;
12+
13+
namespace libmexclass::opentelemetry {
14+
15+
struct ProcessedAttributes {
16+
std::list<std::pair<std::string, common::AttributeValue> > Attributes;
17+
std::list<std::vector<double> > DimensionsBuffer; // list of vector, to hold the dimensions of array attributes
18+
std::list<std::string> StringBuffer; // list of strings as a buffer to hold the string attributes
19+
std::list<std::vector<nostd::string_view> > StringViewBuffer; // list of vector of strings views, used for string array attributes only
20+
};
21+
} // namespace libmexclass::opentelemetry
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2023 The MathWorks, Inc.
2+
3+
#pragma once
4+
#include "opentelemetry-matlab/common/ProcessedAttributes.h"
5+
6+
#include "opentelemetry/common/attribute_value.h"
7+
#include "opentelemetry/nostd/string_view.h"
8+
9+
#include "MatlabDataArray.hpp"
10+
11+
#include <list>
12+
13+
namespace common = opentelemetry::common;
14+
namespace nostd = opentelemetry::nostd;
15+
16+
namespace libmexclass::opentelemetry {
17+
18+
void processAttribute(const std::string& attrname, // input, attribute name
19+
const matlab::data::Array& attrvalue, // input, unprocessed attribute value
20+
ProcessedAttributes& attrs); // output, processed attributes struct
21+
22+
} // namespace libmexclass::opentelemetry
Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
// Copyright 2023 The MathWorks, Inc.
22

33

4-
#include "opentelemetry-matlab/trace/attribute.h"
4+
#include "opentelemetry-matlab/common/attribute.h"
55

66
#include "opentelemetry/nostd/span.h"
77

88
namespace libmexclass::opentelemetry {
99

1010
void processAttribute(const std::string& attrname, // input, attribute name
1111
const matlab::data::Array& attrvalue, // input, unprocessed attribute value
12-
std::list<std::pair<std::string, common::AttributeValue> >& attrs, // output, processed attribute name-value pair
13-
std::list<std::string >& string_buffer, // buffer to store processed string attribute values
14-
std::list<std::vector<nostd::string_view> >& stringview_buffer, // buffer used only for string array attributes
15-
std::list<std::vector<double> >& dimensions_buffer) // buffer for array dimensions of nonscalar attribute values
12+
ProcessedAttributes& attrs) // output, processed attribute struct
1613
{
1714
std::vector<double> attrvalue_dims_buffer; // dimensions of array attribute, cast to double
1815

@@ -24,69 +21,68 @@ void processAttribute(const std::string& attrname, // input, attribute name
2421
if (nelements == 1) { // scalar case
2522
if (valtype == matlab::data::ArrayType::DOUBLE) {
2623
matlab::data::TypedArray<double> attrvalue_mda = attrvalue;
27-
attrs.push_back(std::pair<std::string, common::AttributeValue>(attrname, attrvalue_mda[0]));
24+
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(attrname, attrvalue_mda[0]));
2825
} else if (valtype == matlab::data::ArrayType::INT32) {
2926
matlab::data::TypedArray<int32_t> attrvalue_mda = attrvalue;
30-
attrs.push_back(std::pair<std::string, common::AttributeValue>(attrname, attrvalue_mda[0]));
27+
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(attrname, attrvalue_mda[0]));
3128
} else if (valtype == matlab::data::ArrayType::UINT32) {
3229
matlab::data::TypedArray<uint32_t> attrvalue_mda = attrvalue;
33-
attrs.push_back(std::pair<std::string, common::AttributeValue>(attrname, attrvalue_mda[0]));
30+
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(attrname, attrvalue_mda[0]));
3431
} else if (valtype == matlab::data::ArrayType::INT64) {
3532
matlab::data::TypedArray<int64_t> attrvalue_mda = attrvalue;
36-
attrs.push_back(std::pair<std::string, common::AttributeValue>(attrname, attrvalue_mda[0]));
33+
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(attrname, attrvalue_mda[0]));
3734
} else if (valtype == matlab::data::ArrayType::LOGICAL) {
3835
matlab::data::TypedArray<bool> attrvalue_mda = attrvalue;
39-
attrs.push_back(std::pair<std::string, common::AttributeValue>(attrname, attrvalue_mda[0]));
36+
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(attrname, attrvalue_mda[0]));
4037
} else { // string
4138
matlab::data::StringArray attrvalue_mda = attrvalue;
42-
//string_buffer.push_back(static_cast<std::string>(attrvalue_mda[0]));
43-
string_buffer.push_back(static_cast<std::string>(*(attrvalue_mda.begin())));
44-
attrs.push_back(std::pair<std::string, common::AttributeValue>(attrname, string_buffer.back()));
39+
attrs.StringBuffer.push_back(static_cast<std::string>(*(attrvalue_mda.begin())));
40+
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(attrname, attrs.StringBuffer.back()));
4541
}
4642
} else { // array case
4743
if (valtype == matlab::data::ArrayType::DOUBLE) {
4844
matlab::data::TypedArray<double> attrvalue_mda = attrvalue;
49-
attrs.push_back(std::pair<std::string, common::AttributeValue>(attrname,
45+
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(attrname,
5046
nostd::span<const double>{&(*attrvalue_mda.cbegin()), &(*attrvalue_mda.cend())}));
5147
} else if (valtype == matlab::data::ArrayType::INT32) {
5248
matlab::data::TypedArray<int32_t> attrvalue_mda = attrvalue;
53-
attrs.push_back(std::pair<std::string, common::AttributeValue>(attrname,
49+
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(attrname,
5450
nostd::span<const int32_t>{&(*attrvalue_mda.cbegin()), &(*attrvalue_mda.cend())}));
5551
} else if (valtype == matlab::data::ArrayType::UINT32) {
5652
matlab::data::TypedArray<uint32_t> attrvalue_mda = attrvalue;
57-
attrs.push_back(std::pair<std::string, common::AttributeValue>(attrname,
53+
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(attrname,
5854
nostd::span<const uint32_t>{&(*attrvalue_mda.cbegin()), &(*attrvalue_mda.cend())}));
5955
} else if (valtype == matlab::data::ArrayType::INT64) {
6056
matlab::data::TypedArray<int64_t> attrvalue_mda = attrvalue;
61-
attrs.push_back(std::pair<std::string, common::AttributeValue>(attrname,
57+
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(attrname,
6258
nostd::span<const int64_t>{&(*attrvalue_mda.cbegin()), &(*attrvalue_mda.cend())}));
6359
} else if (valtype == matlab::data::ArrayType::LOGICAL) {
6460
matlab::data::TypedArray<bool> attrvalue_mda = attrvalue;
65-
attrs.push_back(std::pair<std::string, common::AttributeValue>(attrname,
61+
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(attrname,
6662
nostd::span<const bool>{&(*attrvalue_mda.cbegin()), &(*attrvalue_mda.cend())}));
6763
} else { // string
6864
matlab::data::StringArray attrvalue_mda = attrvalue;
6965
std::vector<nostd::string_view> strarray_attr;
7066
strarray_attr.reserve(nelements);
7167

7268
for (auto itr = attrvalue_mda.begin(); itr < attrvalue_mda.end(); ++itr) {
73-
string_buffer.push_back(static_cast<std::string>(*itr));
74-
strarray_attr.push_back(string_buffer.back());
69+
attrs.StringBuffer.push_back(static_cast<std::string>(*itr));
70+
strarray_attr.push_back(attrs.StringBuffer.back());
7571
}
76-
stringview_buffer.push_back(strarray_attr);
77-
attrs.push_back(std::pair<std::string, common::AttributeValue>(attrname,
78-
nostd::span<const nostd::string_view>{&(*stringview_buffer.back().cbegin()), &(*stringview_buffer.back().cend())}));
72+
attrs.StringViewBuffer.push_back(strarray_attr);
73+
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(attrname,
74+
nostd::span<const nostd::string_view>{&(*attrs.StringViewBuffer.back().cbegin()), &(*attrs.StringViewBuffer.back().cend())}));
7975
}
8076
// Add a size attribute to preserve the shape
8177
std::string sizeattr{attrname + ".size"};
8278
matlab::data::ArrayDimensions::iterator copyfrom;
8379
for (copyfrom = attrdims.begin(); copyfrom != attrdims.end(); ++copyfrom) {
8480
attrvalue_dims_buffer.push_back(static_cast<double>(*copyfrom));
8581
}
86-
dimensions_buffer.push_back(attrvalue_dims_buffer);
87-
attrs.push_back(std::pair<std::string, common::AttributeValue>(sizeattr,
88-
nostd::span<const double>{&(*dimensions_buffer.back().cbegin()),
89-
&(*dimensions_buffer.back().cend())}));
82+
attrs.DimensionsBuffer.push_back(attrvalue_dims_buffer);
83+
attrs.Attributes.push_back(std::pair<std::string, common::AttributeValue>(sizeattr,
84+
nostd::span<const double>{&(*attrs.DimensionsBuffer.back().cbegin()),
85+
&(*attrs.DimensionsBuffer.back().cend())}));
9086
}
9187
}
9288
} // namespace

api/trace/+opentelemetry/+trace/Span.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function addEvent(obj, eventname, varargin)
114114
eventtime = posixtime(datetime("now"));
115115
end
116116

117-
eventname = opentelemetry.utils.mustBeScalarString(eventname);
117+
eventname = opentelemetry.common.mustBeScalarString(eventname);
118118
attrs = obj.processAttributes(varargin);
119119
obj.Proxy.addEvent(eventname, eventtime, attrs{:});
120120
end
@@ -132,7 +132,7 @@ function setStatus(obj, status, description)
132132
% new status is not valid, ignore
133133
return
134134
end
135-
description = opentelemetry.utils.mustBeScalarString(description);
135+
description = opentelemetry.common.mustBeScalarString(description);
136136
obj.Proxy.setStatus(status, description);
137137
end
138138

api/trace/+opentelemetry/+trace/Tracer.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121

122122
end
123123
end
124-
spname = opentelemetry.utils.mustBeScalarString(spname);
124+
spname = opentelemetry.common.mustBeScalarString(spname);
125125
id = obj.Proxy.startSpan(spname, contextid, spankind, starttime, ...
126126
attributekeys, attributevalues, links{:});
127127
spanproxy = libmexclass.proxy.Proxy("Name", ...

api/trace/+opentelemetry/+trace/TracerProvider.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
end
4242
% name, version, schema accepts any types that can convert to a
4343
% string
44-
import opentelemetry.utils.mustBeScalarString
44+
import opentelemetry.common.mustBeScalarString
4545
trname = mustBeScalarString(trname);
4646
trversion = mustBeScalarString(trversion);
4747
trschema = mustBeScalarString(trschema);

api/trace/include/opentelemetry-matlab/trace/TracerProviderProxy.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#include "opentelemetry/trace/provider.h"
1515
#include "opentelemetry/trace/noop.h"
1616

17-
#define OTEL_MATLAB_VERSION "0.1.0"
18-
1917
namespace trace_api = opentelemetry::trace;
2018
namespace trace_sdk = opentelemetry::sdk::trace;
2119
namespace trace_exporter = opentelemetry::exporter::otlp;

api/trace/include/opentelemetry-matlab/trace/attribute.h

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)