Skip to content

Commit 9530d62

Browse files
authored
uniform alias name of *Ptr and make_* usage (#111)
1 parent bd7a7e5 commit 9530d62

18 files changed

+98
-83
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,23 @@ Tracing span will be delivered from `sw8` and `sw8-x` HTTP headers. For more det
8787
Then, you can create propagated span object by decoding these items.
8888

8989
```cpp
90-
SpanContextPtr parent_span = createSpanContext(parent);
90+
SpanContextSharedPtr parent_span = createSpanContext(parent);
9191
```
9292

9393
#### Create span
9494

9595
First, you must create tracing context that holds all spans, then crete initial entry span.
9696

9797
```cpp
98-
TracingContextPtr tracing_context = tracer->newContext();
99-
TracingSpanPtr tracing_span = tracing_context->createEntrySpan();
98+
TracingContextSharedPtr tracing_context = tracer->newContext();
99+
TracingSpanSharedPtr tracing_span = tracing_context->createEntrySpan();
100100
```
101101

102102
After that, you can create another span to trace another workload, such as RPC to other services.
103103
Note that you must have parent span to create secondary span. It will construct parent-child relation when analysis.
104104

105105
```cpp
106-
TracingSpanPtr current_span = tracing_context->createExitSpan(current_span);
106+
TracingSpanSharedPtr current_span = tracing_context->createExitSpan(current_span);
107107
```
108108
109109
Alternative approach is RAII based one. It is used like below,
@@ -125,8 +125,8 @@ Note that TracingContext is unique pointer. So when you'd like to send data, you
125125
to avoid undefined behavior.
126126

127127
```cpp
128-
TracingContextPtr tracing_context = tracer->newContext();
129-
TracingSpanPtr tracing_span = tracing_context->createEntrySpan();
128+
TracingContextSharedPtr tracing_context = tracer->newContext();
129+
TracingSpanSharedPtr tracing_span = tracing_context->createEntrySpan();
130130

131131
tracing_span->startSpan("sample_workload");
132132
tracing_span->endSpan();

cpp2sky/internal/async_client.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ struct StreamCallbackTag {
138138
};
139139

140140
template <class RequestType, class ResponseType>
141-
using AsyncStreamPtr = std::shared_ptr<AsyncStream<RequestType, ResponseType>>;
141+
using AsyncStreamSharedPtr =
142+
std::shared_ptr<AsyncStream<RequestType, ResponseType>>;
142143

143144
} // namespace cpp2sky

cpp2sky/internal/stream_builder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ClientStreamingStreamBuilder {
2828
/**
2929
* Create async stream entity
3030
*/
31-
virtual AsyncStreamPtr<RequestType, ResponseType> create(
31+
virtual AsyncStreamSharedPtr<RequestType, ResponseType> create(
3232
AsyncClient<RequestType, ResponseType>& client,
3333
std::condition_variable& cv) = 0;
3434
};
@@ -45,7 +45,7 @@ class UnaryStreamBuilder {
4545
/**
4646
* Create async stream entity
4747
*/
48-
virtual AsyncStreamPtr<RequestType, ResponseType> create(
48+
virtual AsyncStreamSharedPtr<RequestType, ResponseType> create(
4949
AsyncClient<RequestType, ResponseType>& client, RequestType request) = 0;
5050
};
5151

cpp2sky/propagation.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class SpanContext {
6969
virtual const std::string& targetAddress() const = 0;
7070
};
7171

72-
using SpanContextPtr = std::shared_ptr<SpanContext>;
72+
using SpanContextSharedPtr = std::shared_ptr<SpanContext>;
7373

7474
enum class TracingMode {
7575
Default,
@@ -85,10 +85,10 @@ class SpanContextExtension {
8585
virtual TracingMode tracingMode() const = 0;
8686
};
8787

88-
using SpanContextExtensionPtr = std::shared_ptr<SpanContextExtension>;
88+
using SpanContextExtensionSharedPtr = std::shared_ptr<SpanContextExtension>;
8989

90-
SpanContextPtr createSpanContext(absl::string_view ctx);
90+
SpanContextSharedPtr createSpanContext(absl::string_view ctx);
9191

92-
SpanContextExtensionPtr createSpanContextExtension(absl::string_view ctx);
92+
SpanContextExtensionSharedPtr createSpanContextExtension(absl::string_view ctx);
9393

9494
} // namespace cpp2sky

cpp2sky/tracer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ class Tracer {
2929
/**
3030
* Start new segment. It will be called per request, for example.
3131
*/
32-
virtual TracingContextPtr newContext() = 0;
33-
virtual TracingContextPtr newContext(SpanContextPtr span) = 0;
32+
virtual TracingContextSharedPtr newContext() = 0;
33+
virtual TracingContextSharedPtr newContext(SpanContextSharedPtr span) = 0;
3434

3535
/**
3636
* Send SegmentContext to the collector.
3737
*/
38-
virtual bool report(TracingContextPtr obj) = 0;
38+
virtual bool report(TracingContextSharedPtr obj) = 0;
3939
};
4040

4141
using TracerPtr = std::unique_ptr<Tracer>;

cpp2sky/tracing_context.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class TracingSpan {
175175
virtual bool finished() const = 0;
176176
};
177177

178-
using TracingSpanPtr = std::shared_ptr<TracingSpan>;
178+
using TracingSpanSharedPtr = std::shared_ptr<TracingSpan>;
179179

180180
class TracingContext {
181181
public:
@@ -204,28 +204,29 @@ class TracingContext {
204204
/**
205205
* Get spans generated by this segment context.
206206
*/
207-
virtual const std::list<TracingSpanPtr>& spans() const = 0;
207+
virtual const std::list<TracingSpanSharedPtr>& spans() const = 0;
208208

209209
/**
210210
* Get span context which generated this segment context as parent.
211211
*/
212-
virtual SpanContextPtr parentSpanContext() const = 0;
212+
virtual SpanContextSharedPtr parentSpanContext() const = 0;
213213

214214
/**
215215
* Get span context extension which generated this segment context.
216216
*/
217-
virtual SpanContextExtensionPtr parentSpanContextExtension() const = 0;
217+
virtual SpanContextExtensionSharedPtr parentSpanContextExtension() const = 0;
218218

219219
/**
220220
* Generate a segment span related with this segment context.
221221
* @param parent_span Parent span which is extracted from caller.
222222
*/
223-
virtual TracingSpanPtr createExitSpan(TracingSpanPtr parent_span) = 0;
223+
virtual TracingSpanSharedPtr createExitSpan(
224+
TracingSpanSharedPtr parent_span) = 0;
224225

225226
/**
226227
* Generate root segment span, called once per workload.
227228
*/
228-
virtual TracingSpanPtr createEntrySpan() = 0;
229+
virtual TracingSpanSharedPtr createEntrySpan() = 0;
229230

230231
/**
231232
* Generate sw8 value to send SegmentRef.
@@ -264,15 +265,15 @@ class TracingContext {
264265
virtual std::string logMessage(absl::string_view message) const = 0;
265266
};
266267

267-
using TracingContextPtr = std::shared_ptr<TracingContext>;
268+
using TracingContextSharedPtr = std::shared_ptr<TracingContext>;
268269

269270
/**
270271
* RAII based span creation. It acquired then create new span with required
271272
* properties. The span wiil be closed and set end time when called destructor.
272273
*/
273274
class StartEntrySpan {
274275
public:
275-
StartEntrySpan(TracingContextPtr tracing_context,
276+
StartEntrySpan(TracingContextSharedPtr tracing_context,
276277
absl::string_view operation_name)
277278
: span_(tracing_context->createEntrySpan()) {
278279
span_->startSpan(operation_name.data());
@@ -283,15 +284,16 @@ class StartEntrySpan {
283284
span_->endSpan();
284285
}
285286

286-
TracingSpanPtr get() { return span_; }
287+
TracingSpanSharedPtr get() { return span_; }
287288

288289
private:
289-
TracingSpanPtr span_;
290+
TracingSpanSharedPtr span_;
290291
};
291292

292293
class StartExitSpan {
293294
public:
294-
StartExitSpan(TracingContextPtr tracing_context, TracingSpanPtr parent_span,
295+
StartExitSpan(TracingContextSharedPtr tracing_context,
296+
TracingSpanSharedPtr parent_span,
295297
absl::string_view operation_name)
296298
: span_(tracing_context->createExitSpan(parent_span)) {
297299
span_->startSpan(operation_name.data());
@@ -302,10 +304,10 @@ class StartExitSpan {
302304
span_->endSpan();
303305
}
304306

305-
TracingSpanPtr get() { return span_; }
307+
TracingSpanSharedPtr get() { return span_; }
306308

307309
private:
308-
TracingSpanPtr span_;
310+
TracingSpanSharedPtr span_;
309311
};
310312

311313
} // namespace cpp2sky

example/sample.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int main() {
4242
svr.Get("/ping", [&](const httplib::Request& req, httplib::Response& res) {
4343
std::string context = req.get_header_value(kPropagationHeader.data());
4444

45-
TracingContextPtr tracing_context;
45+
TracingContextSharedPtr tracing_context;
4646

4747
if (!context.empty()) {
4848
// 2. Create tracing context with propagated information.

source/cds_impl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void GrpcAsyncConfigDiscoveryServiceStream::onReadDone() {
7676
// But it will be destroyed when new stream created.
7777
}
7878

79-
AsyncStreamPtr<CdsRequest, CdsResponse>
79+
AsyncStreamSharedPtr<CdsRequest, CdsResponse>
8080
GrpcAsyncConfigDiscoveryServiceStreamBuilder::create(
8181
AsyncClient<CdsRequest, CdsResponse>& client, CdsRequest request) {
8282
return std::make_shared<GrpcAsyncConfigDiscoveryServiceStream>(

source/cds_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class GrpcAsyncConfigDiscoveryServiceClient final
5151
UnaryStreamBuilderPtr<CdsRequest, CdsResponse> builder_;
5252
grpc::CompletionQueue& cq_;
5353
grpc::TemplatedGenericStub<CdsRequest, CdsResponse> stub_;
54-
AsyncStreamPtr<CdsRequest, CdsResponse> stream_;
54+
AsyncStreamSharedPtr<CdsRequest, CdsResponse> stream_;
5555
};
5656

5757
class GrpcAsyncConfigDiscoveryServiceStream final
@@ -92,7 +92,7 @@ class GrpcAsyncConfigDiscoveryServiceStreamBuilder final
9292
: config_(config) {}
9393

9494
// AsyncStreamFactory
95-
AsyncStreamPtr<CdsRequest, CdsResponse> create(
95+
AsyncStreamSharedPtr<CdsRequest, CdsResponse> create(
9696
AsyncClient<CdsRequest, CdsResponse>& client,
9797
CdsRequest request) override;
9898

source/grpc_async_client_impl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void GrpcAsyncSegmentReporterStream::onWriteDone() {
149149
onIdle();
150150
}
151151

152-
AsyncStreamPtr<TracerRequestType, TracerResponseType>
152+
AsyncStreamSharedPtr<TracerRequestType, TracerResponseType>
153153
GrpcAsyncSegmentReporterStreamBuilder::create(
154154
AsyncClient<TracerRequestType, TracerResponseType>& client,
155155
std::condition_variable& cv) {

0 commit comments

Comments
 (0)