Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roll The Dice Getting Started for C++ #3345

Closed
svrnm opened this issue Oct 4, 2023 · 9 comments
Closed

Roll The Dice Getting Started for C++ #3345

svrnm opened this issue Oct 4, 2023 · 9 comments
Labels
enhancement New feature or request help wanted Extra attention is needed sig:cpp

Comments

@svrnm
Copy link
Member

svrnm commented Oct 4, 2023

To complete #2623 we need an updated version of the C++ Getting Started with a "Roll The Dice" app. To simplify things one could use oatpp or drogon or any other C++-based framework.

@svrnm svrnm added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Oct 4, 2023
@Akhaled19
Copy link
Contributor

Hi @svrnm, I would like to work on this! I just need to figure out a few things

@svrnm
Copy link
Member Author

svrnm commented Oct 5, 2023

@Akhaled19 that's great to hear, thank you!

To provide you with some help, here are a few pointers:

  • Take a look at the Rust & Swift getting started, they represent good examples of what we are aiming for as a starting point: provide code for a roll the dice webserver, instrument it, provide pointers to next steps.
  • My own C++ skills are rusty, but I have an oatpp app as a starting point for you, if you like to take that as an example (not a requirement, just a suggestion, use whatever framework suits you):
#include "oatpp/web/server/HttpConnectionHandler.hpp"
#include "oatpp/network/Server.hpp"
#include "oatpp/network/tcp/server/ConnectionProvider.hpp"

class Handler : public oatpp::web::server::HttpRequestHandler {
public:
  std::shared_ptr<OutgoingResponse> handle(const std::shared_ptr<IncomingRequest>& request) override {
    std::string response = std::to_string(1 + (std::rand() % 6));
    return ResponseFactory::createResponse(Status::CODE_200, response);
  }
};

void run() {
  auto router = oatpp::web::server::HttpRouter::createShared();
  router->route("GET", "/rolldice", std::make_shared<Handler>());
  auto connectionHandler = oatpp::web::server::HttpConnectionHandler::createShared(router);
  auto connectionProvider = oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", 8000, oatpp::network::Address::IP_4});
  oatpp::network::Server server(connectionProvider, connectionHandler);
  OATPP_LOGI("MyApp", "Server running on port %s", connectionProvider->getProperty("port").getData());
  server.run();
}

int main() {
  oatpp::base::Environment::init();
  run();
  oatpp::base::Environment::destroy();
  return 0;
}

@Akhaled19
Copy link
Contributor

@svrnm thank you for the helpful pointers!

@svrnm
Copy link
Member Author

svrnm commented Oct 6, 2023

@Akhaled19 sure, let us know if you need any more help and don't hesitate to raise your PR early to get feedback!

@Akhaled19
Copy link
Contributor

Hi @svrnm I managed to get the app up and running but I'm having a hard time linking OpenTelemetry with my oatpp Application. I'm new to cmake. Here is what my CMakeLists.txt file looks like
Screen Shot 2023-10-15 at 5 52 04 PM

@svrnm
Copy link
Member Author

svrnm commented Oct 16, 2023

@Akhaled19, if you share the work you have done so far in textual form (snippets here in the comments or even a github repo!), making it easier for us to take a look into what you have tried to accomplish so far.

@open-telemetry/cpp-approvers

@svrnm
Copy link
Member Author

svrnm commented Oct 17, 2023

Note that C++11 support has been dropped: open-telemetry/opentelemetry-cpp#2342

@svrnm svrnm added the sig:cpp label Oct 18, 2023
@Akhaled19
Copy link
Contributor

Got it. I will work on the pr

@marcalff
Copy link
Member

@svrnm Please close, was fixed by PR #3423

@svrnm svrnm closed this as completed Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed sig:cpp
Projects
None yet
Development

No branches or pull requests

3 participants